Jenarroyo Jenarroyo - 1 year ago 122
PHP Question

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

Here is my code, for some reasons.. it is working perfectly fine in my localhost and it can send email with HTML content and is rendered perfectly. When I upload my codes on the production, the email seems to be in text format and all the HTML tags are shown. What to do with this kind of issue?

There are no errors and email is sent (based from the error info on the last part of the code), its just the rendering of the BODY Im having trouble with. Thanks!


//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

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

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

//Tell PHPMailer to use SMTP

//Enable SMTP debugging

$mail->SMTPDebug = 2;

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

//Set the hostname of the mail server
$mail->Host = '';

//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('', '');

//Set who the message is to be sent to
$mail->addAddress('', '');

//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;">
<div style="background-color: #e8c020; padding: 2px;"></div>

//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!";

This question in now closed. Thank you! You may check the answer from below.

Answer Source

Calling the isHTML() method after the $mail->Body has been set solved the problem for me:

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

Issue now closed! Thanks :D

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download