php - 使用 phpmailer 通过电子邮件发送 html 页面
问题描述
我正在尝试通过电子邮件发送此 html 页面。这是由 unlayer.com 完成的。我已经用 $mail->isHtml(true), ... msgHtml 进行了测试...但是在电子邮件客户端中总是看到代码或部分代码而不是 html 页面...。你有什么想法吗?谢谢 !!!
这是我的代码:
$sql = "SELECT * FROM Idiomes_Lin WHERE Id = 992";
$stmt = $con->prepare($sql);
$stmt->execute();
$row = $stmt->fetch();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Enviar Email
require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
include ("emaildata.php");
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 4;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP_HOST; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SMTP_UNAME; // SMTP username
$mail->Password = SMTP_PWORD; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->AuthType = 'tls';
$mail->Port = SMTP_PORT;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);// TCP port to connect to
$mail->From = 'it@ipe-innovaciones.com';
$mail->FromName = 'IT';
// Mail del sol·licitant
$mail->addAddress('it@ipe-innovaciones.com'); // Add a recipient
$mail->Subject = 'Test email';
$Missatge = $row['Nom1'];
$mail->Body = html_entity_decode($Missatge);
$mail->isHTML(true);
$mail->send();
我需要发送的代码在这个链接中:(我不能在这个输入中复制粘贴,所以很奇怪)
https://app.guvavet.com/testenviaremail.php
非常感谢您的帮助。
解决方案
$mail->msgHTML(file_get_contents('yourHtml.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body
推荐阅读
- python - 在 TensorFlow 2.0 中,如何将 TFRecord 数据提供给 keras 模型?
- android - 如何停止在输入法中触发“updateCursor”事件?
- machine-learning - 在嵌入式系统上加载经过训练的模型(无库)
- typescript - 带有扩展另一个类的类的打字稿定义文件(自动生成)
- linux - How to access local variables in remote server using ssh
- spring - 谁能解释一下 JdbcClientDetailsServiceBuilder 的使用?
- javascript - 以角度将HTML页面导出为pdf
- javascript - 通过 Chromecast cast_sender.js 流式传输时出错
- mysql - 无论如何,是否只将唯一条目插入到 MYSQL 中的数据透视表中?
- c# - .NET:从域和子文件夹重定向到新域,保留路径和查询字符串,在 web.config 中使用 httpredirect