This morning Amazon announced availability of a bulk email delivery service called "Simple Email Service". Anyone who knows how much pain is it to set-up scalable email solution (and it is not just spammers who need it!) should celebrate the occasion. I know of a company that spent several years cleaning ip addresses it sends email and found itself locked into the contract with internet provider since it would take forever to reach required level of email deliver ability anywhere else.
Anyway, this evening I decided to check the Amazon claim that the service is "simple". Found out that it is indeed simple!
Since there is not much in terms of the documentation yet, here is my code where I used AWS PHP library:
Anyway, this evening I decided to check the Amazon claim that the service is "simple". Found out that it is indeed simple!
Since there is not much in terms of the documentation yet, here is my code where I used AWS PHP library:
// Enable full-blown error reporting. http://twitter.com/rasmus/status/7448448829
error_reporting(-1);
// Set plain text headers
header("Content-type: text/plain; charset=utf-8");
// Include the SDK
require_once '../sdk.class.php';
// Instantiate the Amazon class
$ses = new AmazonSES();
//what's our quota?
$rQuota = $ses->get_send_quota();
$quota24 = (int) $rQuota->body->GetSendQuotaResult->Max24HourSend;
$sentCnt = (int) $rQuota->body->GetSendQuotaResult->SentLast24Hours;
echo("we can send max of $quota24 per 24 hrs and we sent $sentCnt so far\n");
//verify sender email (do it once per sender!)
//$ses->verify_email_address('dispose@gmail.com');
//print_r($ses->list_verified_email_addresses());
//send email
$source = 'dispose@gmail.com';
$destination = CFComplexType::map(array('ToAddresses'=>'x@gmail.com', 'CcAddresses'=>'x@hotmail.com'));
$message = CFComplexType::map(array('Subject.Data'->'test email', 'Body.Text.Data'->'test message ' . rand(100, 1000)));
$rSendEmail = $ses->send_email($source, $destination, $message);
if ($rSendEmail->status==200) {
$emailId = $rSendEmail->body->SendEmailResult->MessageId;
echo("sent test email with id: $emailId\n");
}
else {
print_r($rSendEmail);
}
Comments
If you want to send html emails, just change :
CFComplexType::map(array('Subject.Data'->'test email', 'Body.Text.Data'->'test message ' . rand(100, 1000)));
with this:
Body.Html.Data
Thanks Again!
J.
I want to add a lot of HTML code to my emails and various apostrophes, inverted commas, etc, may throw the embedded text emails off.
My suggestion is two use two template files, one for HTML body of the email, and the other for plain text. In the code you can change addressee name and whatever other information you may have before sending it. And you do need to worry about inverted commas, UNICODE characters, or any escaping as library will take care of correct email encoding