Amazon-SES integration for PHPMailer
This time we have come up with a very easy to use solution to integrate Amazon-SES with everyone’s favorite PHPMailer library and you are free to use it anyway you want. [ Thanks to the power of GNU LGPL license ] The solution is a slightly modified version of PHPMailer with an Amazon-SES backend.
Note that, this is a completely different implementation than Aaron Parecki’s one in GitHub. One of our clients wanted to have an Amazon-SES backend with minimal extra dependency, least amount of required extra syntax and complete code compatibility with PHPMailer. So, we implemented part of Amazon-SES API in PHP without using the AWS SDK and modified PHPMailer-5.1 slightly to suit our need. Also, the error messages produced are a bit more verbose. This worked out to be quite useful as lot’s of things, specially address verification requirement can give a lot of pain to Amazon-SES users.
Warning: You must have PHP5.0 or higher to use it.
You can download our modified PHPMailer from here.
Edit: This bugfix release fixes two bugs, one related to improper DKIM signing and other related to ignoring ‘cc’/’bcc’ headers. Thanks to Antonello and Manish for the bug reports.
Here's an example of using the Amazon-SES backend of PHPMailer -
<?php 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 = "email@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 */ ?>