我无法以 HTML 格式发送邮件,它显示代码 PHPMailer

问题描述 投票:0回答:1

PHP 科杜姆

例如,我将 HTML 代码视为纯文本

<blockquote> <p><strong>hello</strong></p>
//Server settings
$mail->isSMTP();                                            //Send using SMTP
$mail->Host       = settings('smtpHost');                     //Set the SMTP server to send through
$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
$mail->Username   = settings('smtpUsername');                     //SMTP username
$mail->Password   = settings('smtpPassword');                               //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
$mail->Port       = settings('smtpPort');                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

//Recipients
$mail->setFrom(settings('smtpSendMail'), settings('smtpName'));
//Content
$mail->isHTML(true);
$mail->CharSet = 'utf-8';
//Set email format to HTML
$mail->Subject = $subjectMail;
$mail->Body = $bodyMail;       

邮件中显示Html代码

我在 Youtube 上观看了视频并查看了有关堆栈溢出的旧线程,但我无法解决问题。

php phpmailer
1个回答
0
投票

我在 PHPMailer 中遇到了同样的问题,我发现以下解决方案适用于我的代码。

$mail->Body = nl2br($html);
© www.soinside.com 2019 - 2024. All rights reserved.