Amazon Web Services(AWS) - Simple Email Service

Amazon Simple Email Service provides a simple way to send e-mails without having to maintain your own mail server.  This PHP class is a REST-based interface to that service.

First, you’ll need to create a SimpleEmailService class object:

For this first you need to get ses.php file - http://sourceforge.net/projects/php-aws-ses/

require_once('ses.php'); $ses = new SimpleEmailService('Access Key Here', 'Secret Key Here');

If this is your first time using Simple Email Service, you will need to request verification of at least one e-mail address, so you can send messages:

print_r($ses->verifyEmailAddress('user@example.com')); ------- Array ( [RequestId] => 1b086469-291d-11e0-85af-df1284f62f28 )

Every request you make to SimpleEmailService will return a request id. After you’ve requested verification, you’ll get an e-mail at that address with a link. Click the link to get your address approved.  Once you’ve done that, you can use it as the ‘From’ address in the e-mails you send through SES.  If you don’t have production access yet, you’ll also need to request verification for all addresses you want to send mail to.

print_r($ses->listVerifiedEmailAddresses()); ------- Array ( [RequestId] => 77128e89-291d-11e0-986f-43f07db0572a [Addresses] => Array ( [0] => user@example.com [1] => recipient@example.com ) )

Removing an address from the verified address list is just as easy:

$ses->deleteVerifiedEmailAddress('user@example.com');

The only thing left to do is send an e-mail, so let’s try it. First, you’ll need a SimpleEmailServiceMessage object.  Then, you’ll want to set various properties on the message.  For example:

$m = new SimpleEmailServiceMessage(); $m->addTo('recipient@example.com'); $m->setFrom('user@example.com'); $m->setSubject('Hello, world!'); $m->setMessageFromString('This is the message body.'); print_r($ses->sendEmail($m)); ------- Array ( [MessageId] => 0000012dc5e4b4c0-b2c566ad-dcd0-4d23-bea5-f40da774033c-000000 [RequestId] => 4953a96e-29d4-11e0-8907-21df9ed6ffe3 )

You can set multiple to/cc/bcc/replyto addresses, either individually or all at once:

$m->addTo('jim@example.com'); $m->addTo(array('dwight@example.com', 'angela@example.com')); $m->addCC('holly@example.com'); $m->addCC(array('kelly@example.com', 'ryan@example.com')); $m->addBCC('michael@example.com'); $m->addBCC(array('kevin@example.com', 'oscar@example.com')); $m->addReplyTo('andy@example.com'); $m->addReplyTo(array('stanley@example.com', 'erin@example.com'));

If you have both a text version and an HTML version of your message, you can set both:

$m->setMessageFromString($text, $html);

Finally, if you need to specify the character set used in the subject or message:

$m->setSubjectCharset('ISO-8859-1'); $m->setMessageCharset('ISO-8859-1');