-
Notifications
You must be signed in to change notification settings - Fork 31
/
AmazonSESMailer.php
94 lines (84 loc) · 3.48 KB
/
AmazonSESMailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
.---------------------------------------------------------------------------.
| Software: Amazon SES Mailer - PHP email class for Amazon SES |
| Version: 1.0 |
| Contact: dev@geoloqi.com |
| Info: https://github.com/geoloqi/Amazon-SES-Mailer-PHP |
| ------------------------------------------------------------------------- |
| Admin: Aaron Parecki |
| Authors: Aaron Parecki aaronpk@geoloqi.com |
| Copyright (c) 2011, Geoloqi.com |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
'---------------------------------------------------------------------------'
*/
require_once('AWSSDKforPHP/sdk.class.php');
require_once('AWSSDKforPHP/services/ses.class.php');
require_once('PHPMailer-lite.php');
class AmazonSESMailer extends PHPMailerLite {
public $AWSAccessKeyId;
public $AWSSecretKey;
public $Mailer = 'amazonses';
public function __construct($id, $key, $exceptions=FALSE) {
$this->AWSAccessKeyID = $id;
$this->AWSSecretKey = $key;
parent::__construct($exceptions);
}
/**
* Sends mail using Amazon SES.
* @param string $header The message headers
* @param string $body The message body
* @access protected
* @return bool
*/
protected function AmazonSESSend($header, $body) {
$ses = new AmazonSES($this->AWSAccessKeyID, $this->AWSSecretKey);
$ses = new AmazonSES(array(
"key" => $this->AWSAccessKeyID,
"secret" => $this->AWSSecretKey
));
if ($this->SingleTo === true) {
foreach ($this->SingleToArray as $key => $val) {
$response = $ses->send_raw_email(array(
'Data' => base64_encode($header . "\n" . $body)
), array(
'Source' => $this->From,
'Destinations' => $val
));
// implement call back function if it exists
$isSent = ($response->isOK()) ? 1 : 0;
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
if(!$isSent) {
throw new phpmailerException('Error Sending via Amazon SES [Type: '.$response->body->Error->Type.", Code: ".$response->body->Error->Code.", Message: ".$response->body->Error->Message."]", self::STOP_CRITICAL);
}
}
} else {
$response = $ses->send_raw_email(array(
'Data' => base64_encode($header . "\n" . $body)
), array(
'Source' => $this->From,
'Destinations' => $this->to
));
// implement call back function if it exists
$isSent = ($response->isOK()) ? 1 : 0;
$this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
if(!$isSent) {
throw new phpmailerException('Error Sending via Amazon SES [Type: '.$response->body->Error->Type.", Code: ".$response->body->Error->Code.", Message: ".$response->body->Error->Message."]", self::STOP_CRITICAL);
}
}
return true;
}
protected function GetSendFunction($mailer) {
switch($mailer) {
case 'amazonses':
return 'AmazonSESSend';
default:
return parent::GetSendFunction($mailer);
}
}
}