PHP 邮件编码主题行
当我尝试从 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.
相关文章