PHP未知发件人

时间:2013-01-14 15:44:45

标签: php html forms web

您好我是PHP的新手,目前还不太了解。我已经修改了一个联系表单,因为邮件直接进入垃圾邮件会遇到一些问题。

我认为这是因为(未知发件人)一直在电子邮件标题中显示。如果有人能帮我纠正这个,我将不胜感激。以下是我在网站上实施的代码:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Wirral PT Enquiry'; 
$to = 'joebloggs@hotmail.com'; 
$subject = 'Wirral PT Enquiry';
$human = $_POST['human'];
$headers = "enquiry@wirralpt.co.uk";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";

if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if ($human == '2') {                 
            if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p> 1+1=2!! </p>';
        }
    } else {
        echo '<p>You need to fill everything!!</p>';
    }
} 
?>

4 个答案:

答案 0 :(得分:5)

$from = 'From: Wirral PT Enquiry';应包含“来自”电子邮件地址,而不仅仅是名称:

 $from = 'From: Wirral PT Enquiry <enquiry@wirralpt.co.uk>'; 

试试吗?

答案 1 :(得分:1)

尝试使用

$headers = "Reply To :enquiry@wirralpt.co.uk";

可能会为你工作

另外,

$headers = "From :enquiry@wirralpt.co.uk";

与您相关的电子邮件ID尝试这两个

答案 2 :(得分:1)

将标题更改为:

$headers = 'From: enquiry@wirralpt.co.uk' . "\r\n" .
    'Reply-To: enquiry@wirralpt.co.uk' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

你的邮件应该是这样的:

mail ($to, $subject, $body, $headers)

答案 3 :(得分:-2)

如果在使用PhpMailer的SMTP设置时,也会导致此错误,$ mail-&gt; IsSMTP();错过了