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 邮件编码主题行
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
