Created
October 4, 2016 13:41
-
-
Save TiagoGouvea/28a61f970eae3913cbaacc59ddea010f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function sendEmail($email, $subject, $html, $text) | |
{ | |
$sesClient = SesClient::factory(array( | |
'credentials' => array( | |
'key' => 'YOURKEY', | |
'secret' => 'YOURSECRET', | |
), | |
'region' => 'us-east-1', | |
'version' => '2010-12-01' | |
)); | |
$from_name = base64_encode($this->title); | |
$fromMail = "=?utf-8?B?$from_name?= <".trim($this->mail_from).">"; | |
$args = array( | |
'Source' => $fromMail, | |
'Destination' => array( | |
'ToAddresses' => array($email) | |
), | |
'Message' => array( | |
'Subject' => array( | |
'Data' => $subject, | |
'Charset' => 'utf-8', | |
), | |
'Body' => array( | |
'Text' => array( | |
'Data' => $text, | |
'Charset' => 'utf-8', | |
), | |
'Html' => array( | |
'Data' => $html, | |
'Charset' => 'utf-8', | |
), | |
), | |
) | |
); | |
$exceptionMessage = null; | |
$result = null; | |
try { | |
/* @var $result \Aws\Result */ | |
$result = $sesClient->sendEmail($args); | |
} catch (\Aws\Ses\Exception\SesException $e) { | |
$exceptionMessage = $e->getMessage(); | |
echo $exceptionMessage; | |
} | |
$success = $result != null && $result['@metadata']['statusCode'] == 200; | |
if ($success) { | |
$message = null; | |
$messageId = $result->get('MessageId'); | |
} else { | |
$message = $exceptionMessage; | |
$messageId = null; | |
} | |
$return = array( | |
'success' => $success, | |
'message' => $message, | |
'message_id' => $messageId); | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment