Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created December 16, 2014 14:11
Show Gist options
  • Save kopiro/f411da4ea440a7b1abf1 to your computer and use it in GitHub Desktop.
Save kopiro/f411da4ea440a7b1abf1 to your computer and use it in GitHub Desktop.
Use Amazon SES to override wp_mail() - with champagne
<?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
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment