使用PHPMailer时获取电子邮件主题中的垃圾字符。如何解决这个问题?

时间:2019-11-26 17:06:18

标签: 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;
}

这是什么问题? 非常感谢。

0 个答案:

没有答案