首页 > 解决方案 > 使用 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;
}

这里有什么问题?太感谢了。

标签: phpphpmailer

解决方案


推荐阅读