繁体   English   中英

使用AWS SES,如何将电子邮件内容转换为HTML?

[英]Using AWS SES, how to make the email content to HTML?

由于某些原因,这是我的代码。.在我的本地主机中,它运行良好,并且可以发送带有HTML内容的电子邮件,并且呈现效果很好。 当我在作品上上传代码时,电子邮件似乎是文本格式,并且显示了所有HTML标签。 如何处理此类问题?

没有错误,并且发送了电子邮件(基于代码最后一部分的错误信息),只是BODY Im的呈现存在问题。 谢谢!

<?php

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have   access to that
date_default_timezone_set('Etc/UTC');

require '../phpmailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging

$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'email-smtp.us-west-2.amazonaws.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
// I tried PORT 25, 465 too
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

// Username to use for SMTP authentication - use full email address for gmail 
$mail-> Username = "USERNAME"; 

// Password to use for SMTP authentication 
$mail-> Password = "PASSWORD"; 

//Set who the message is to be sent from
$mail->setFrom('from@email.com', '');

//Set who the message is to be sent to
$mail->addAddress('example@email.com', '');



//Set the subject line
$mail->Subject = 'TEST Mail';

//this is just an example content
$mail->Body = '
<div style="background-color:#254a64;">
    <div align="center" style="color:white; padding:20px 0px 10px 5px; font-size: 1.5em; font-family:Arial;">
       SAMPLE HEADER
    </div>
</div>
<div style="background-color: #e8c020; padding: 2px;"></div> 
<br><br>';

//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body ALT BODYYYY';

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

该问题现已关闭。 谢谢! 您可以从下面查看答案。

设置$ mail-> Body后,调用isHTML()方法可以为我解决问题:

$mail->Body    = $Body;
$mail->IsHTML(true);       // <=== call IsHTML() after $mail->Body has been set.

问题现已关闭! 感谢:D

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM