Home / php-aws-ses-0.8.0
Name Modified Size InfoDownloads / Week
Parent folder
ses.php 2011-02-01 21.1 kB
changelog.txt 2011-02-01 152 Bytes
readme.txt 2011-02-01 5.0 kB
Totals: 3 Items   26.2 kB 0
This PHP class is extremely easy to use.  A few examples are sufficient explanation.

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

<?php
  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:

<?php
  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.
This id may be useful if you need to contact AWS about any problems.  For brevity,
I will omit the request id if it is the only value returned from a service call.

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.

If you want to see what addresses have been verified on your account, it's easy:

<?php
  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:

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

This call will return a request id if you need it.

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:

<?php
  $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));
?>

You'll get both a request id and a message id back from the service:

-------
Array
(
    [MessageId] => 0000012dc5e4b4c0-b2c566ad-dcd0-4d23-bea5-f40da774033c-000000
    [RequestId] => 4953a96e-29d4-11e0-8907-21df9ed6ffe3
)
-------

And that's all there is to it!



There are a few more things you can do with this class.
You can make two informational queries, try these out:

<?php
  print_r($ses->getSendQuota());
  print_r($ses->getSendStatistics());
?>

For brevity I will not show the output of those two API calls.

This information will help you keep track of the health of your account.
See the Simple Email Service documentation for more information on these calls:

http://docs.amazonwebservices.com/ses/latest/APIReference/API_GetSendQuota.html
http://docs.amazonwebservices.com/ses/latest/APIReference/API_GetSendStatistics.html

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

<?php
  $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'));
?>

These calls are cumulative, so in the above example, three addresses end up
in each of the To, CC, and BCC fields.

You can also set one or more Reply-To addresses:

<?php
  $m->addReplyTo('andy@example.com');
  $m->addReplyTo(array('stanley@example.com', 'erin@example.com'));
?>

You can set a return path address:

<?php
  $m->setReturnPath('noreply@example.com');
?>

You can use the contents of a file as the message text instead of a string:

<?php
  $m->setMessageFromFile('/path/to/some/file.txt');
?>

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

<?php
  $m->setMessageFromString($text, $html);
  // or from a file instead:
  $m->setMessageFromFile($textfilepath, $htmlfilepath);
?>

Remember that setMessageFromString and setMessageFromFile are mutually exclusive.
If you call both, only the second call will be used.

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

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

The default is UTF-8 if you do not specify a charset, which is usually the right setting.
You can read more information here:
http://docs.amazonwebservices.com/ses/latest/APIReference/API_Content.html

Currently, this library does not support the SendRawEmail call, which means you cannot send
emails with attachments or custom headers.  Support for that API is planned for the next version.
It will be seamlessly integrated into the SimpleEmailServiceMessage object, so you will not
have to worry about whether you should call SendEmail or SendRawEmail.

Source: readme.txt, updated 2011-02-01