본문 바로가기

Web Service/AWS

SES 이용하여 메일 보내기

PHPMailer – Amazon SES Integration

Hello World,

This time we have come up with a very easy to use solu­tion to inte­grate Ama­zon SES with everyone’s favorite PHP­Mailer library and you are free to use it any­way you want. [ Thanks to the power of GNU LGPL license :) ] The solu­tion is a slightly mod­i­fied ver­sion of PHP­Mailer with an Ama­zon SES backend.

Note that, this is a com­pletely dif­fer­ent imple­men­ta­tion than Aaron Parecki’s one in GitHub. One of our clients wanted to have an Ama­zon SES back­end with min­i­mal extra depen­dency, least amount of required extra syn­tax and com­plete code com­pat­i­bil­ity with PHP­Mailer. So, we imple­mented part of Ama­zon SES APIin PHP with­out using the AWS SDK and mod­i­fied PHPMailer-5.1 slightly to suit our need. Also, the error mes­sages pro­duced are a bit more ver­bose. This worked out to be quite use­ful as lot’s of things, espe­cially address ver­i­fi­ca­tion require­ment can give a lot of pain to Ama­zon SES users.

Warn­ingYou must have php5.0 or higher to use it.

Replac­ing your cur­rent phpmailer:

Just down­load the fol­low­ing pack­age and extract and replace your cur­rent “php­mailer” folder with it:

Edit: This bug­fix release fixes two bugs, one related to improper DKIM sign­ing and other related to ignor­ing ‘cc’/’bcc’ head­ers. Thanks to Antonello and Man­ish for the bug reports. :)

PHPMAILER_5.1_WITH_AMAZON_SES

Here’s an exam­ple to use the Ama­zon SES backend:

require_once('class.phpmailer.php');
 
$mail = new phpmailer;
 
// Set mailer to use AmazonSES.
$mail-> IsAmazonSES();
 
// Set AWSAccessKeyId and AWSSecretKey provided by amazon.
$mail-> AddAmazonSESKey("AWSAccessKeyId", "AWSSecretKey");
 
// "From" must be a verified address.
$mail-> From = "nobody@example.com";
$mail-> FromName = "Nobody";
 
$mail-> AddAddress("Somebody@example.com", "Somebody");
$mail-> Subject = "A test mail from phpmailer using Amazon SES.";
$mail-> Body = "Looks like it works!";
$mail-> Send(); // send message
 
/* End of File */

If you need com­mer­cial sup­port inte­grat­ing it with your project, con­tact us.