PHP mail()没有收到电子邮件

时间:2016-08-28 23:33:39

标签: php html

我正在尝试设置一个与我联系的页面,目前我已经让它一直工作到发送的消息的位置'结果正确显示。但是,我的收件箱中的电子邮件从未出现过。

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $antispam = $_POST['antispam'];
    $to = 'myemailaddress@gmail.com';
    $from = 'From : ' . $email;

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if ($antispam == '10' || 'Ten' || 'ten') {
        $human = true;
    }

    if($_POST['submit'] &&  $name != "" && $email != "" && $message != "" && $subject != "") {
        if ($human == true) {
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }
        } else {
            $result = "You answered the anti-spam answer incorrectly. Please try again.";
        }
    } else {
        $result = "You did not fill out a required field. Please try again.";
    }

?>

<?php echo $result; ?>

我已经单独读过Gmail有问题的邮件(),这可能是原因吗?

1 个答案:

答案 0 :(得分:1)

我找到了答案,老老实实地感到笨拙,因为没有认出来。

从未告知发送电子邮件,只是检查发送是否真实。我知道这听起来很奇怪,但这是旧代码:

         if ($human == true) {
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }

这是固定版本

         if ($human == true) {
            mail($to, $subject, $body, $from);
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }

简而言之,我在检查后添加mail($to, $subject, $body, $from);以查看if $human == true