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

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

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

赞赏!

4

2 回答 2

6

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

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

mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers);
于 2011-08-25T12:28:57.993 回答
-1

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

PS:Hotmail 很烂。:)

于 2011-08-25T12:25:34.030 回答