問題描述
當我嘗試從 PHP 發送 HTML 編碼的電子郵件時,如果主題行包含特殊字符,例如 "這是您請求的信息"
,PHP 會將其編碼為讀取 "Here'是您請求的信息."
When I try to send a HTML encoded email from PHP, if the subject line contains special chars like "Here's the information you requested"
, PHP encodes it to read "Here's the information you requested."
我該如何解決這個問題?
How do I fix this?
以下是使用 PHP mail() 的代碼:
Here's what the code looks like using PHP mail():
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$headers .= 'To: ' . $mod_params['name'] . '<' . $mod_params['email'] . '>' . "
";
$headers .= 'From: <do_not_reply@a4isp.com>' . "
";
$email_to = $mod_params['email'];
$email_sub = "Here's the Information You Requested";
$body = html_entity_decode("<html><body>" . $email_html_body . "</body></html>");
mail($email_to,$email_sub,$body,$headers);
它給出與通過 SugarPHPMailer 類運行它相同的錯誤.
It gives the same error as running it through the SugarPHPMailer class.
推薦答案
試試這個:
$newsubject='=?UTF-8?B?'.base64_encode($subject).'?=';
這樣您就不必依賴 PHP 或 MTA 的編碼,您就可以完成工作,并且郵件客戶端應該理解它.您的新主題中不會出現特殊字符,因此在發送電子郵件時不會出現任何問題.
This way you don't rely on PHP or the MTA's encoding, you do the job, and the mail client should understand it. No special characters will be present in your new subject, so no problems should arise while delivering the email.
這篇關于PHP 郵件編碼主題行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!