使用PHP向Hotmail发送电子邮件时出现编码问题

时间:2011-08-25 12:18:44

标签: php email encoding 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

我很困惑。我已经用Google搜索了几天,并尝试了不同类型的解决方案,但我没有任何成功,我担心。

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

赞赏!

2 个答案:

答案 0 :(得分:6)

电子邮件主题和其他标题内容(如姓名)使用RFC 2047

进行编码

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

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

答案 1 :(得分:-1)

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

P.S。:Hotmail很糟糕。 :)

相关问题