首页 > 解决方案 > 使用 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

非常感谢您的帮助。

标签: phphtmlemailphpmailer

解决方案


$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

推荐阅读