【问题标题】:PHP Mail Headers are Being Sent Within The BodyPHP 邮件标头在正文中发送
【发布时间】:2012-04-30 22:58:46
【问题描述】:
function sendEmail($address,$subject,$message)
{
    $headers = "Reply-To: miloAds Team <admin@miloads.com>\r";
    $headers .= "Return-Path: miloAds Team <admin@miloads.com>\r";
    $headers .= "From: miloAds Team <admin@miloads.com>\r"; 
    $headers .= "Organization: Milonas Media LLC\r";
    $headers .= "MIME-Version: 1.0\r";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r";
    $headers .= "X-Priority: 3\r";
    $headers .= "X-Mailer: PHP". phpversion() ."\r";

    mail($address, $subject, $message, $headers); 
}

发送电子邮件时,标题出现在正文中。

【问题讨论】:

  • 顺便说一句,Return-Path 不是可以设置的标头,邮件服务器必须设置它。

标签: php email


【解决方案1】:

尝试将每个\r 转义更改为\r\n,看看是否有帮助。

PHP manual:

additional_headers(可选)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc).
Multiple extra headers should be separated with a CRLF (\r\n).

确保在最后一个标题中包含尾随 \r\n

还要确保从$subject 中删除任何换行符,因为这可能会导致问题。看看这些是否有帮助。

【讨论】:

  • 我只使用了\n,它对我来说一直很好用。
  • @MatthewJordan 也来自手册...Note: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.
  • 您能否在邮件客户端中查看消息源,以便查看完整的原始消息内容。您应该会看到一个标头,其后有 2 个换行符,将标头与正文分开。
【解决方案2】:

\n添加到\r,即\r\n并删除最后一个:

function sendEmail($address,$subject,$message)
{
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
    $headers .= "From: miloAds Team <admin@miloads.com>\r\n"; 
    $headers .= "Reply-To: miloAds Team <admin@miloads.com>\r\n";
    $headers .= "Organization: Milonas Media LLC\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion();

    mail($address, $subject, $message, $headers); 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2015-02-02
    • 2016-04-06
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多