Sending HTML emails from Amazon SES using the PHP SDK

I am working on a service that sends emails from AWS SES. I could send plain text letters, but I need to send rich HTML letters in one of the cases. This is the code I'm using:

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 = ' abc@www..com '; $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 placed inside tables. I tried both send_email and send_raw_email, but both of them did not work. Do I need to do something extra or something else?

+4
source share
3 answers

I know this old question, but still writing the answer. And hope this helps someone in the 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)); 
+4
source

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

 require_once('ses.php'); $ses = new SimpleEmailService('accessKey', 'secretKey'); $m = new SimpleEmailServiceMessage(); $m->addTo(' addressee@example.com '); $m->setFrom('Name < yourmail@example.com >'); $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/

+3
source

I tried using the SES SDK and it was not easy to work with. I ended up using PHPMailer to connect to SES via SMTP. First configure SMTP access from Amazon SES, and then add these lines to PHPMailer so that it connects to SES via TLS:

 $mail = new PHPMailer(); $mail->IsSMTP(true); $mail->SMTPAuth = true; $mail->Mailer = "smtp"; $mail->Host= "tls://email-smtp.us-east-1.amazonaws.com"; $mail->Port = 465; $mail->Username = ""; // SMTP username (Amazon Access Key) $mail->Password = ""; // SMTP Password (Amazon Secret Key) // ... the rest of PHPMailer code here ... 

PHPMailer is very good at rich email (with text backup), inline images and attachments.

+2
source

Source: https://habr.com/ru/post/1481364/


All Articles