php - 使用 PHPMailer 时在电子邮件主题中获取垃圾字符。如何解决这个问题?
问题描述
我正在使用 PHPMailer 5.1,在通过 PHPMailer 发送电子邮件时,我收到了一些垃圾字符,例如=?UTF-8?Q??=
,而不是主题中的预期文本。
这是我使用的代码:
$recipient = 'xxx@xxx.cz';
$sender = 'xxx@xxx.cz';
header("Access-Control-Allow-Origin: *");
try
{
if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST')
{
throw new ErrorException('Method Not Allowed (please use POST)', 405);
}
$data = unserialize(base64_decode($_POST['_data']));
$_POST = unserialize(base64_decode($_POST['_post']));
ob_start();
$cislo_objednavky = 1 + (int)
file_get_contents('cpo/cpo.txt');
require 'tabulka.php';
$body = ob_get_contents();
ob_end_clean();
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(TRUE);
$mail->CharSet = 'UTF-8';
$mail->Host = "xxx.xxxx.cz";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Username = "xxx@xxx.cz";
$mail->Password = "xxxxx";
$mail->Encoding = 'base64';
$mail->AddAddress($recipient);
$mail->SetFrom($sender, 'XXXXXX');
$mail->AddReplyTo($sender);
$mail->AddCC($_POST['email']);
$mail->Subject = ('Objednávka č.'.$cislo_objednavky);
$mail->MsgHTML('html tělo mailu');
$mail->Send();
file_put_contents('xxxx.xxx', $cislo_objednavky);
}
catch (Exception $e)
{
header('HTTP/1.0 '.$e->getCode().' '.$e->getMessage());
echo '<h1>'.($e->getMessage().' (#'.$e->getCode().')').'</h1>';
exit;
}
这里有什么问题?太感谢了。
解决方案
推荐阅读
- javascript - 使用 Azure Active Directory 授权从 Angular 静态网页前端调用 Azure Functions API
- python - 用于处理字符串的 Pandas lambda 函数语法
- c# - C# tls1.3 异常:无法联系本地安全机构
- java - 使用参数初始化类字段的不同方法
- php - Laravel CSV 导入器未定义的偏移量:1
- javascript - 在同一个新标签 javascript 中打开多个 url,然后停止最后一个
- c++ - 可以获得 Gmutex 锁的线程所有者吗?
- javascript - 未捕获的 TypeError formiobuilder 不是函数。我做错什么了?
- c# - 如何以编程方式使用在 Window.Resources 中定义的 GroupStyle?
- html - 如何在反应中加载带有脚本标签的外部静态 HTML 页面?