PHP邮件代码将邮件发送到垃圾邮件/隔离区

时间:2012-06-13 15:58:22

标签: php

标题解释了自己。这是一个内部员工互相买卖的网站。它仅基于Microsoft Outlook电子邮件地址。所有电子邮件都应该在卖家发送电子邮件时发送。除非我在动作php页面上输入<php phpinfo(); ?>,否则它会告诉我sendmail_from属性是从服务器上的虚假电子邮件发送的。它似乎是php脚本发送的自动电子邮件。这可能是电子邮件被发送到垃圾邮件的原因,因为电子邮件无效。此外,我在线阅读有关完整和有效标题但大多数标题似乎是可选的,我无法找到解释最佳标题的任何地方。我的邮件代码:

//send approval email to the approver
    $from = isset($_POST['from'])? $_POST['from']:1;
    $message = isset($_POST['message'])? $_POST['message']:1;
    $message = $message . '<a href="http://dev-corkboard/newapproval.php?id='
        .$result[0][0].'"> Click here to approve website post.</a>';
// In case any of our lines are larger than 70 characters, we should use
// wordwrap()
    $message = wordwrap($message, 70);
    $to      = 'clehane@eatonvance.com';
    $replyto = isset($_POST['replyto'])? $_POST['replyto']:1;
    $subject = isset($_POST['subject'])? $_POST['subject']:1;
    $headers = "MIME-Version: 1.0" . "\r\n" . 'From: "'.$from.'"' . "\r\n" .
       'Reply-To: "'.$replyto.'"' . "\r\n" .
       'Content-Type:text/html;charset=iso-8859-1' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
    if (mail($to, $subject, $message, $headers)) {
        //test message for email
    }               
    header ("location: newindex.php");  `

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

和bam!解决了它,需要把电子邮件地址这样:

$from = 'MyName <myemail@mycompany.com>';

我还包括这些标题:

"X-Priority: 0\r\n".
"X-MSMail-Priority: Normal\r\n".
"X-Mailer: mycompany.com