An API wrapper and control panel for the Amazon Simple Email Service (SES). Includes a ready Zend_Mail transport class for easy integration (commercial versions).
Amazon Simple Email Service (Amazon SES) is a scalable and cost-effective Email delivery service for businesses and developers. Benefits include Email delivery optimizations - highly increasing the chances that Emails do not get caught as SPAM, notifications on bounces, rejections or complaints, and very low costs compared to alternatives (10 cents per 1000 Emails).
This class provides a wrapper for the Amazon SES API as well as a control panel to view account information and manage verified addresses.
Zend Framework, for seamless integration with
Integration is simple once you have signed up to the Amazon SES service (see Usage instructions for more details).
To get started, you need to first sign-up to the Amazon Simple Email Service.
Once your account is active and you have access to your security keys, you can start using the API. To configure the class with your security keys you have two options:
Example using a configuration array:
$ses = new Lionite_AmazonSES( array ( 'accessKey' => 'SJVndj58Eghks98Eajgb68', 'privateKey' => 'Jntu4bvf739d/g8bts9h57gaGNvhs85024nfNfjdgh856jd' ));
Important: before you can send Emails, you must verify the Email addresses you intend to send from and to. Use the
verifyEmail() method described on this page to do that, and click on the link in the verification Email sent to that address.
You can request production access from AWS to skip verifying recipient Email address.
This method is intended for direct use in your scripts.
$recipients parameter can be either an Email string or an array of Emails. Advanced recipient types ('to','cc','bcc') can be specified by using indexed arrays. For example:
$recipients = array( 'to' => array('email@example.com' => 'John Doe'), // 'To' address 'bcc' => array('firstname.lastname@example.org' => 'Jane Joe') // 'Bcc' address );
Note: you can use 'email' => 'name' pairs in the array to have named recipients.
$from parameter can be either an Email string or an array of Emails, similar to the
$recipients parameter. Instead of recipient types, you can specify the source of the Email (sent from) and the reply to addresses. Note that the source of the Email must be a verified Email address (see the
verifyEmail() method below).
$from = array( 'source' => array('email@example.com' => 'Site name'), // 'From' address 'reply' => array('firstname.lastname@example.org' => 'Your name') // 'Reply-to' address );
$subject parameter is a string containing the subject line.
$body parameter can either be a string containing text body, or an array specifying HTML or mixed body. Use 'text' and 'html' as the array indexes to indicate body type. For example:
$body = array( 'text' => 'This is a text version of the body', 'html' => 'This is an HTML version of the body' );
This method is intended for use by abstraction classes that generate Email headers, such as Zend_Mail and SwiftMailer. Direct input of Email headers allows a greater degree of control over advanced Email options. A transport class for Zend_Mail is included in this package.
$to parameter can be either an Email string or an array of Email recipients. Compose the headers appropriately to control body type, recipients types and other advanced options.
$from parameter should contain an Email string and must be a verified Email address (see below).
$headers parameters are strings containing the raw Email body and headers.
Verifying Email addresses is required to be able to send Emails. You can only send from verified addresses, and if you don't have production access yet you can only send to verified Email addresses as well.
This method accepts an Email address string for verification purposes. A verification Email will be sent to that addresses with a verification link. After the link is pressed, the address will be verified and you can use it to send and receive Emails using the SES service.
This method removes an Email address from the verified Email list.
This method returns an array of the verified Email addresses.
The Amazon SES provides several methods to get data about the status of your account. A control panel that retrieves and formats this data is included in this package.
This method returns an array of the Email sending quotas - how many Emails were sent in the last 24 hours, how many can be sent every 24 hours and the maximum send rate per second.
This methods returns an array of usage statistics for your SES account. It includes Email sending numbers, rejections, bounces and complaints, grouped by time.
The Amazon SES API provides several methods to get data about and manage your account. This package includes a ready control panel template that retrieves and formats account data and provides simple access to account management actions. See the screenshots for example data.
The control panel script is located at
/examples/manage.php. Internally it uses a simple templating system that renders
/examples/manage.phtml which is a template ready for use with many templating engines (such as Zend_View and Savant). You can use the control panel script as is or modify it and the template to suit your needs. It includes basic styling that can be seen in the screenshots to the right.
Along with the control panel, several example scripts are provided with this package -
Is used to send verification Email from an 'email' parameter in the $_GET array.
Is used to remove a verified Email address from an 'email' parameter in the $_GET array.
Is an example form that uses the
sendEmail() method to demonstrate the basic way to send Emails.
Included in this package is a transport class for Zend_Mail for easy integration - it is not required at all for using the base API wrapper though. It is located under
As with other Zend_Mail transport classes, you pass an instance of the transport class into the
send() method. Example:
$mail = new Zend_Mail(); // Set Email options such as recipient, subject and body $transport = new Lionite_Mail_Transport_SES(); $mail -> send($transport);
You can pass your SES account security keys to the constructor of the transport class, the same as you would for the
$transport = new Lionite_Mail_Tranport_SES( array ( 'accessKey' => 'SJVndj58Eghks98Eajgb68', 'privateKey' => 'Jntu4bvf739d/g8bts9h57gaGNvhs85024nfNfjdgh856jd' ));
This is not needed if the
Lionite_AmazonSES class is configured with your security keys.