php - 通过 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';
}
解决方案
推荐阅读
- ruby-on-rails - VSCode、Docker、Rails 调试
- electron - 如何通过 Electron desktopCapturer 截取包括双屏在内的屏幕截图
- javascript - 什么是 JavaScript 中字符串连接的时间复杂度
- android - 以编程方式隐藏自动完成文本视图中的向下箭头
- postgresql - postgresql 函数中的 beginTransaction 和 commit
- authentication - 如何根据 cookie 对用户进行身份验证?
- typescript - 如何使我的模型对于 sequelize 方法是可选的 - 打字稿
- vba - VBA Application.FollowHyperlink 如何将 http 标头发送到 Web 服务器,例如 User-Agent
- android-emulator - Pepper Android Emulator 卡在 34%
- c - 递归链表在 C 中输出乱码