0
votes

I am a complete noob in AWS. I configured AWS SES today and now I am able to send an email to a recipient using this code.

<?php

// Replace [email protected] with your "From" address. 
// This address must be verified with Amazon SES.
define('SENDER', 'sender email');        

// Replace [email protected] with a "To" address. If your account 
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'recipient email');  

// Replace smtp_username with your Amazon SES SMTP user name.
define('USERNAME','my username');  

// Replace smtp_password with your Amazon SES SMTP password.
define('PASSWORD','my password');  

// If you're using Amazon SES in a region other than US West (Oregon), 
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP  
// endpoint in the appropriate region.
define('HOST', 'email-smtp.us-west-2.amazonaws.com');  

 // The port you will connect to on the Amazon SES SMTP endpoint.
define('PORT', '587');     

// Other message information                                               
define('SUBJECT','Hello from Driffle!');
define('BODY','Test Email');

require_once 'Mail.php';

$headers = array (
  'From' => SENDER,
  'To' => RECIPIENT,
  'Subject' => SUBJECT);

$smtpParams = array (
  'host' => HOST,
  'port' => PORT,
  'auth' => true,
  'username' => USERNAME,
  'password' => PASSWORD
);

 // Create an SMTP client.
$mail = Mail::factory('smtp', $smtpParams);

// Send the email.
$result = $mail->send(RECIPIENT, $headers, BODY);

if (PEAR::isError($result)) {
  echo("Email not sent. " .$result->getMessage() ."\n");
} else {
  echo("Email sent!"."\n");
}

?>

But when I try to send an html formatted email. The output email returns plain text. Looking for a solution to send html emails through Amazon SES.

2
Go through the guide docs.aws.amazon.com/ses/latest/DeveloperGuide/… and Google your title.Funk Forty Niner
@Fred-ii- I followed that guide only to send emails, but my question is how to send them as HTML with images and custom fonts.Mayank Chawla
use html markup and image source using a full urlFunk Forty Niner
You must inline images and css to html elements because email providers block external sources. If this isn't complicated enough, each and every email provider have their own set of rules, meaning some elements work in 1 while not in the other. There is no standard so be prepared to have a template ready for each email provider.Xorifelse
I am also searching for this solution.. Mayank's point, I believe, is that the above example sends a text email regardless of markup. SMTP does not know that the content is HTML. I've tried adding the headers that tell it so, but they cause the send to fail. Several other things I've tried also fail. AWS documentation on this is ridiculously absent.huygir

2 Answers

0
votes

Found it. I was doing it a bit wrong, but this works...

Add these headers:

'Mime-Version' => '1.0', 'Content-Type' => 'text/html; charset="ISO-8859-1"',

Then submit the body as HTML markup (keep it simple as possible to begin with - it does not need to be a "page" necessarily).

bh

0
votes

added content-type in $headers . It worked for me

require_once 'Mail.php';

$headers = array (
'Content-Type' => "text/html; charset=UTF-8",  // <- add this line 
'From' => SENDER,
'To' => RECIPIENT,
'Subject' => SUBJECT);