mail()函数无法正常工作

时间:2016-08-15 08:06:01

标签: php

我必须遵循有效的代码,但不是我想要的代码

if(isset($_POST['edit']) && $_POST['edit']!="")
{
    // Email Information
    $firstName = $_POST['fname'];
    $lastName = $_POST['lname'];
    $mobile = $_POST['contactNumber'];
    $comments = $_POST['message'];
    $email_from = $_POST['email'];
    $email_to = "info@munsterweddingdjs.com";
    //$email_headers = "From: ". $firstName ." ". $lastName . " <" . $email_from . ">\r\n" . "Reply-To: info@munsterweddingdjs.com";
    $email_headers = "From: $firstName $lastName <kevin@yourwebsite.com>" . "\r\n" . "Reply-To: info@munsterweddingdjs.com";


    $email_subject = "Munster Wedding DJs Inquiry!";
    $email_body = "\nName: " . $firstName . " " . $lastName .
    "\nEmail: " . $email_from . 
    "\nPhone Number: " . $mobile . 
    "\nMessage: " . $comments;

    // Send Email
    $mailerResult = @mail($email_to, "$email_subject", $email_body,
    $email_headers, '-f ' . $email_from);

    // Check For Errors
    if($mailerResult) {

        //echo "Mail Sent!";
        echo '<script>document.location.href="thanks.html#anchor"</script>';
        exit();

    } else {

        //  echo "Error Sending Email!" . "<br><br>";
        //  print_r(error_get_last());
    }

}

如果我改变

From: $firstName $lastName <kevin@yourwebsite.com>"

From: $firstName $lastName <$email_from>" 

表格没有发送电子邮件? 这是为什么?

我想要做的就是接收电子邮件,当我点击回复时,它会将用户的电子邮件地址放入&#34; to&#34;字段。

1 个答案:

答案 0 :(得分:0)

尝试使用这样的,     &amp; lt; for&lt;     &strong;&gt;

&amp; gt;

删除&amp; lt ;

之间的空格
$email_headers = "From: $firstName $lastName &lt; $email_from &gt;" . "\r\n" . "Reply-To: info@munsterweddingdjs.com";