使用PHP发送电子邮件到Hotmail时的编码问题

3
我正在使用以下代码向我的网站成员发送电子邮件。脚本可以正常工作,用户可以收到电子邮件。但是,当发送电子邮件到Hotmail或Notes时,我遇到了编码问题。
代码如下:
$to       = "to@email.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset="utf-8"; format="flowed"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";
$headers .= "To: John Doe<john@doe.com>" . "\r\n" . 
"From: John Smith<john@smith.com" . "\r\n" .
"Reply-To: john@doe.com" . "\r\n" .
"Return-Path: john@doe.com" . "\r\n" .
"Sender: john@doe.com" . "\r\n" .
"X-Sender: john@doe.com" . "\r\n" .
"X-Mailer: JohnDoe". "\r\n".
"X-Report-Abuse: Please report abuse to: john@doe.com";

//If the e-mail was successfully sent...
$subject = $translation[104];
if(mail($to, $subject, $message, $headers)){

}

消息和主题都包含瑞典字母Å、Ä和Ö。实际消息在Hotmail中正确编码并显示,而主题则不是。您可以查看下面的图片获取更多信息:

图片:http://www.aspkoll.se/imgo/649

我很困惑。我已经搜索了几天并尝试了不同种类的解决方案,但恐怕没有任何成功。

您能否帮助我解决这个问题?

感激不尽!


邮件头中不能有非ASCII字符。这违反了规则。 - tchrist
2个回答

6

邮件主题和其他头部内容(如名称)使用RFC 2047进行编码。

mail()的php.net评论提供以下示例:

mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers);

-1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接