我的 PHP 脚本向用户发送电子邮件,当电子邮件到达他们的邮箱时,主题行 ($subject
) 有这样的字符a^£
添加到我的主题文本的末尾。这显然是和编码问题有关。电子邮件内容本身很好,只是主题行被破坏了。
我到处寻找但找不到如何正确编码我的主题.
这是我的标题。请注意,我正在使用Content-Type
with charset=utf-8
and Content-Transfer-Encoding: 8bit
.
//set all necessary headers
$headers = "From: $sender_name<$from>\n";
$headers .= "Reply-To: $sender_name<$from>\n";
$headers .= "X-Sender: $sender_name<$from>\n";
$headers .= "X-Mailer: PHP4\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "MIME-Version: 1.0\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: 3\n";
$headers .= "Date: $date\n";
$headers .= "Delivered-to: $to\n";
$headers .= "Return-Path: $sender_name<$from>\n";
$headers .= "Envelope-from: $sender_name<$from>\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
Update要获得更实用和最新的答案,请查看帕莱克的回答.
指定的字符编码内容类型只描述消息正文的字符编码,而不描述消息头。您需要使用编码字 syntax与任一引用可打印编码 or the Base64编码:
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
您可以使用imap_8bit为了引用可打印编码和base64_encode对于 Base64 编码:
"Subject: =?UTF-8?B?".base64_encode($subject)."?="
"Subject: =?UTF-8?Q?".imap_8bit($subject)."?="
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)