N
N
NelsonEmpty2017-05-02 10:03:09
PHP
NelsonEmpty, 2017-05-02 10:03:09

Sendmail script not working correctly?

There is a problem with the sendmail script, mail is sent without problems, but forwarded fields like Name E-mail and Message text are empty.
Script code

<?php
  header('Content-type: application/json');
  $status = array(
    'type'=>'success',
    'message'=>'Письмо отправлено!'
  );

    $name = @trim(stripslashes($_POST['name'])); 
    $email = @trim(stripslashes($_POST['email'])); 
    $subject = @trim(stripslashes($_POST['subject'])); 
    $message = @trim(stripslashes($_POST['message'])); 

    $email_from = '****@***.***';
    $email_to = '*********@gmail.com';

    $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;

    $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

    echo json_encode($status);
    die;

Form Code
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <input type="text" class="form-control" required="required" placeholder="Ваше имя">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <input type="text" class="form-control" required="required" placeholder="Ваш Email">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="form-group">
                                        <textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Ваше сообщение"></textarea>
                                    </div>
                                    <div class="form-group">
                                        <button type="submit" class="btn btn-danger btn-lg">Отправить</button>
                                    </div>
                                </div>
                            </div>
                        </form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Frank, 2017-05-02
@NelsonEmpty

<input type="text" class="form-control" required="required" placeholder="Ваше имя">
<input type="text" class="form-control" required="required" placeholder="Ваш Email">

You don't have the name
attribute specified Check what is passed in $_POST at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question