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


Encoding problems when sending email with PHP to Hotmail

我使用以下代码发送电子邮件给我的网站的成员。脚本工作,电子邮件被用户接收。但是,我在给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

我很困惑。我在谷歌上搜索了好几天,尝试了各种不同的解决方案,但恐怕没有任何成功。

你能帮我解决这个问题吗?

欣赏!

电子邮件主题和其他头部内容,如名称,使用RFC 2047编码

php.net对mail()的注释给出了以下示例:

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

试试http://www.phpclasses.org/browse/file/919.html。它适用于Yahoo mail, Gmail, Hotmail。

注:: Hotmail烂透了。:)