PHPmailer 发送 HTML 代码

php
2022-08-30 13:33:36

我正在使用PHPmailer发送电子邮件。

我也用过HTML = True内容类型

    $mail = new PHPMailer();

$mail->IsSMTP();                    // send via SMTP
$mail->Host     = $Host; 
$mail->SMTPAuth = true;             // turn on SMTP authentication
$mail->Username = $Username;  
$mail->Password = $Password; 

$mail->From     = $From;
$mail->FromName = $FromName;

    $mail->AddAddress($To , $ToName);

$mail->WordWrap = 50;               // set word wrap
    $mail->Priority = 1; 
$mail->IsHTML(true);  
$mail->Subject  =  $Subject;
$mail->Body     =  $Body;

发送电子邮件后,我看到实际的HTML代码而不是内容,请检查以下内容

enter image description here

**不确定问题是什么**


答案 1

在设置实例属性(我的意思是)后调用该方法为我解决了问题:isHTML()Body$mail->Body

$mail->Subject = $Subject;
$mail->Body    = $Body;
$mail->IsHTML(true);       // <=== call IsHTML() after $mail->Body has been set.

答案 2

有方法,它也调用。msgHTML()IsHTML()

这个名字令人困惑...IsHTML

/**
 * Create a message from an HTML string.
 * Automatically makes modifications for inline images and backgrounds
 * and creates a plain-text version by converting the HTML.
 * Overwrites any existing values in $this->Body and $this->AltBody
 * @access public
 * @param string $message HTML message string
 * @param string $basedir baseline directory for path
 * @param bool $advanced Whether to use the advanced HTML to text converter
 * @return string $message
 */
public function msgHTML($message, $basedir = '', $advanced = false)

推荐