Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending HTML Mails from Amazon SES using PHP SDK

I am working on a service that sends emails from AWS SES service. I have been able to send plain text mails but I require to send rich HTML mails in one of the case. This is the code that I use:

header("MIME-Version: 1.0; Content-type: text/html; charset=iso-8859-1");

    require_once(dirname(__FILE__).'/AWSSDKforPHP/sdk.class.php');

// Instantiate the Amazon class
$ses = new AmazonSES();


$source = '[email protected]';

$dest = array('ToAddresses'=>array($to));

$message = CFComplexType::map(array('Subject.Data'=>$subject, 'Body.Html.Data'=>$message_mail));

$rSendEmail = $ses->send_email($source, $dest, $message);

message_mail is some HTML text put inside tables. I have tried both send_email and send_raw_email but both of them did not work. Do I need to do something extra or different?

like image 986
Himanshu Joshi Avatar asked Jan 13 '23 09:01

Himanshu Joshi


2 Answers

I know it's old question but still writing an answer. And hoping it will help someone in future.

$m = new SimpleEmailServiceMessage();
$m->addTo('receiver email address');
$m->setFrom('send email address');
$m->setSubject('testing!');

$body= '<b>Hello world</b>';
$plainTextBody = '';

$m->setMessageFromString($plainTextBody,$body);    
print_r($ses->sendEmail($m));
like image 149
keen Avatar answered Jan 20 '23 14:01

keen


this worked for me (without using the sdk or smtp):

require_once('ses.php');

$ses = new SimpleEmailService('accessKey', 'secretKey');

$m = new SimpleEmailServiceMessage();
$m->addTo('[email protected]');
$m->setFrom('Name <[email protected]>');
$m->setSubject('You have got Email!');
$m->setMessageFromString('Your message');
$ses->sendEmail($m);

You can get ses.php from http://www.orderingdisorder.com/aws/ses/

like image 42
George Avatar answered Jan 20 '23 15:01

George