首页 > 解决方案 > 通过 smtp 发送邮件时邮件正文变为空

问题描述

我正在尝试使用 SMTP 发送邮件。如果我以简单的文本发送邮件,那么它工作得很好,但是当我在其中添加 HTML 代码(如 b、a 标记)时,邮件正在发送,但我的邮件正文是空的。

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'pushkarnabandhu.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = SMTP_EMAIL;                 // SMTP username
$mail->Password = SMTP_PASSWORD;                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom(SMTP_EMAIL, 'Virtual Music');
$mail->addAddress($_POST['email'],$_POST['name']);     // Add a recipient
// $mail->addAddress('ellen@example.com');               // Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');

// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Email confirmation';
$mail->Body    = "<b><a href='".ROOT."confirm/$$insert[verification_string]'></a></b>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

标签: phpsmtp

解决方案


推荐阅读