Skip to content

Instantly share code, notes, and snippets.

@TiagoGouvea
Created October 4, 2016 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoGouvea/28a61f970eae3913cbaacc59ddea010f to your computer and use it in GitHub Desktop.
Save TiagoGouvea/28a61f970eae3913cbaacc59ddea010f to your computer and use it in GitHub Desktop.
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