使用PHP向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);
标签:php,encoding,email,hotmail 来源: https://codeday.me/bug/20190903/1794968.html