HTML在PHPMailer中显示为纯文本主体

时间:2019-01-09 16:39:03

标签: phpmailer

我很尴尬地问这个问题,因为我已经多次看到这个问题了。但是,这些解决方案似乎都不适合我。我的HTML在通过PHPMailer发送的电子邮件正文中以纯文本形式输出

我已经阅读了Github上的PHPMailer文档,并在stackoverflow上找到了像这样的PHPmailer sending HTML CODE和这个Add HTML formatting in phpmailer的答案。

    //Create a new PHPMailer instance
    $mail = new PHPMailer(true);
    // Set PHPMailer to use the sendmail transport
    $mail->isSendmail();
    //Set who the message is to be sent from
    $mail->setFrom('xxx@yyy.com');
    //Set an alternative reply-to address
    //    $mail->addReplyTo('replyto@example.com', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress('xxx@yyy.com');
    //Set the subject line
    $mail->Subject = 'Rework Report';

    $body = file_get_contents('current/rework.txt');
    $mail->Body= $body;
    $mail->IsHTML = (true);

   //Attach a file
   //$mail->addAttachment('current/rework.txt');
   //send the message, check for errors
   if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }

输出应为电子邮件正文中的HTML。

1 个答案:

答案 0 :(得分:1)

根据问题中的PHPmailer sending HTML CODE链接,您可能需要更改:

// From
$mail->IsHTML = (true);
// To -- i.e. remove the equals sign (=)
$mail->IsHTML(true);

它似乎是函数而不是变量。

相关问题