PHP Mail Encodes Subject Line(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.
这篇关于PHP 邮件编码主题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 邮件编码主题行


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP - if 语句中的倒序 2021-01-01