[英]php mail with utf-8 encoding displays incorrectly in Microsoft mail clients
我搜索並搜索了解決方案,但無濟於事。
我正在使用php郵件發送一個混合的text / html電子郵件,用utf8編碼。 這是相關的代碼:
$headers = "From: $fromPerson\r\n" .
"Content-Transfer-Encoding: 8bit\r\n".
"Reply-To: $fromPerson\r\n" .
"Content-Type: multipart/alternative; boundary=". $mime_boundary_header. "\r\n" .
"X-Mailer: PHP/" . phpversion();
$message = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$textEmail
--$mime_boundary
Content-Type: text/html; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$htmlEmail
--$mime_boundary--";
//mb_detect_encoding($message) returns UTF-8
$mail_sent = @mail( $to, $subject, $message, $headers);
這些消息包含西班牙語以及那些棘手的字符。 這些電子郵件在gmail,hotmail(在線Outlook),mac郵件,電話等方面都很好用,但在Windows Live郵件或Microsoft Outlook中卻沒有。
如果我手動將Windows Live Mail中的默認字體設置為utf8,則消息會正確顯示,但不會顯示。 如果我將來自其他客戶端的電子郵件轉發到Outlook或windows live,它也會顯示正常。
我可以找到工作我敢肯定,但我錯過了什么嗎? 我不想依賴接收器知道如何更改消息的編碼,所以我需要添加到電子郵件中以提示這些客戶端識別編碼嗎?
如果這已經在其他地方處理過,我道歉,我會感激任何建議。 看起來我應該繼續使用PHPMailer來查看是否能解決問題,但出於個人好奇心,了解為什么會發生這種情況會很有趣......
我不確定'
包裹字符集是必要的,甚至是正確的。 嘗試刪除它們:
Content-Type: text/plain; charset=UTF-8
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: example@example.com\r\n";
$headers .= "Reply-To: example@example.com\r\n";
對Riko的回答進行了修改,使得代碼更加清晰。
$header_array = [
"MIME-Version: 1.0",
"Content-type: text/html; charset=UTF-8",
"From: example@example.com",
"Reply-To: example@example.com"
];
$headers = implode("\r\n", $header_array);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.