Created
December 16, 2014 14:11
-
-
Save kopiro/f411da4ea440a7b1abf1 to your computer and use it in GitHub Desktop.
Use Amazon SES to override wp_mail() - with champagne
This file contains hidden or 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
<?php | |
$ses = Aws\Ses\SesClient::factory(array( | |
'key' => SES_KEY, | |
'secret' => SES_SECRET, | |
'region' => SES_REGION | |
)); | |
class SesClientProxyForPHPMailer { | |
private $phpmailer; | |
public function __construct($phpmailer) { | |
$this->phpmailer = $phpmailer; | |
} | |
public function Send() { | |
global $ses; | |
$this->phpmailer->preSend(); | |
try { | |
return $ses->sendRawEmail([ | |
'RawMessage' => [ 'Data' => base64_encode($this->phpmailer->getSentMIMEMessage()) ] | |
]); | |
} catch (Exception $e) { | |
trigger_error($e->getMessage()); | |
throw new phpmailerException($e->getMessage(), $e->getCode()); | |
} | |
} | |
} | |
add_action('phpmailer_init', function(&$phpmailer) { | |
$phpmailer = new SesClientProxyForPHPMailer($phpmailer); | |
}); |
lastguest
commented
Dec 16, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment