PHP联系人表单未发送电子邮件-不确定发生了什么问题

时间:2018-10-24 17:06:55

标签: php contact-form

我正在我的简历网站上工作,但是在正确设置联系表时遇到了问题。每当我填写表格时,它都说成功了,但它从未将表格发送到我的实际电子邮件中,不知道为什么。我有点不知道怎么了。

在错误日志中,将弹出以下两个消息:

[24-Oct-2018 12:46:05 America/New_York] PHP Notice:  Undefined index: first_name in /home/danielqtw/public_html/php/mail_handler.php on line 8
[24-Oct-2018 12:46:05 America/New_York] PHP Notice:  Undefined index: sub in /home/danielqtw/public_html/php/mail_handler.php on line 9

这是mail_handler.php

    <?php


$mailto  = 'danielsnowtt@gmail.com';


$name       = strip_tags($_POST['first_name']);
$sub        = strip_tags($_POST['sub']);
$email      = strip_tags($_POST['email']);
$comments   = strip_tags($_POST['message']);

$subject = "[Contact Form]";

$body = "
<br>
<p><b>Message</b>: $comments</p>
<p><b>Name</b>: $name <br>
<p><b>Subject</b>: $sub <br>
<b>Email</b>: $email<br>
";


$success = "Sent";
$error = "Failed";


$headers = "From: $name <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers2 = "From:" . $mailto;
$message = "<html><body>$body</body></html>";

if(empty($name) || empty($sub) || empty($email) || empty($comments) ){

    echo "Fill The Form Properly"; // message
    header("Location: http://"); //go to home page
    die();

}

else {

    if (mail($mailto, $subject, $message, $headers)) {
        echo "$success"; // success
    } else {
        echo "$error"; // failure
    }
}

这是我的custom.js,其中包含联系表格

  $('form#contact-form').on('submit', function (e) {
            e.preventDefault(); 
            var form = $(this);
            $("#submit").attr('disabled', 'disabled'); 
            var post_data = form.serialize();  
            $('div#form-loader').removeClass('is-hidden').fadeIn(500);
            $.ajax({
                type: 'POST',
                url: 'php/mail_handler.php', 
                data: post_data
            })
                .done(function () {
                    $('div#form-loader').fadeOut(500);
                    Materialize.toast('Message Sent! I will contact you shortly, Thanks', 4000);
                    $("form#contact-form")[0].reset();
                    Materialize.updateTextFields(); 
                    $("#submit").removeAttr('disabled', 'disabled'); 

                })
                .fail(function () {
                    $('div#form-loader').fadeOut(500);
                    Materialize.toast('Sorry! Something Wrong, Try Again', 4000);
                    $("#submit").removeAttr('disabled', 'disabled'); // Enable submit button
                });
        });

由于我没有收到任何电子邮件,所以我对这个问题可能会感到恼火。

预先感谢

0 个答案:

没有答案
相关问题