/mvc/components/amazonSes
[return to app]1 
<?php
2 /**
3  * Interface to Amazon Simple Email Service (Amazon SES)
4  */
5 class amazonSesComponent {
6     /**
7      * Initializes SES
8      * @return SimpleEmailService
9      */
10     protected function _ses() {
11         if (!class_exists('SimpleEmailService')) {
12             require get::$config->packagesPath() . 'amazon-ses';
13         }
14         $ses = new SimpleEmailService(get::$config->AMAZON['accessKey'], get::$config->AMAZON['secretKey']);
15         $ses->enableVerifyPeer(false);
16         return $ses;
17     }
18 
19     /**
20      * Sends an email via Amazon SES
21      *
22      * Uses approximately the same method-signature as the email method that ships with Vork, so a drop in
 replacement
23      * for get::component('email')->sendEmail($args) that sends via the PHP mail() method using your local SMTP
 server.
24      *
25      * Required argument keys are: to, from, subject, body
26      * Optional key is: (boolean) html
27      *
28      * Depends on SimpleEmailService package from http://www.orderingdisorder.com/aws/ses/
29      * @param array $args - Valid keys are from, to, subject, body, (bool) html
30      */
31     public function sendEmail(array $args) {
32         extract($args);
33         $ses = $this->_ses();
34 
35         $m = new SimpleEmailServiceMessage();
36         $m->setFrom($from);
37         $m->addTo($to);
38         $m->setSubject($subject);
39         if (isset($html) && $html) {
40             $m->setMessageFromString(strip_tags($body), $body);
41         } else {
42             $m->setMessageFromString($body);
43         }
44 
45         return $ses->sendEmail($m);
46     }
47 
48     /**
49      * Amazon requires all sender-addresses be verified before email will be delivered
50      * During initial sandbox testing, recipient addresses must be verified too
51      *
52      * @param string $email
53      */
54     public function sesVerifyEmailAddress($email) {
55         return $this->_ses()->verifyEmailAddress($email);
56     }
57 }


