public function send() { $content = $this->do_replace($this->content); if (static::$sending_method == static::METHOD_SENDMAIL) { return mail(implode(',', $this->recipients['']), $this->do_replace($this->subject), $content); } else { if (static::$sending_method == static::METHOD_SES) { require_once root . '/library/aws.phar'; $controller = new \Aws\Ses\SesClient(['version' => 'latest', 'profile' => _ini::get('aws', 'profile'), 'region' => _ini::get('aws', 'region', 'eu-west-1')]); return $controller->sendEmail(['Source' => _ini::get('email', 'from_address'), 'Destination' => ['ToAddresses' => $this->recipients[''], 'CcAddresses' => $this->recipients['cc'], 'BccAddresses' => $this->recipients['bcc']], 'Message' => ['Subject' => ['Data' => $this->subject, 'Charset' => 'UTF8'], 'Body' => ['Text' => ['Data' => '', 'Charset' => 'UTF8'], 'Html' => ['Data' => $content, 'Charset' => 'UTF8']]]]); } } }
/** * https://eu-west-1.console.aws.amazon.com/ses/home?region=eu-west-1#verified-senders-domain */ function send(array $params = [], &$error_message = '') { require_php_lib('aws_sdk_v3'); $error_message = null; try { $ses = Aws\Ses\SesClient::factory(['credentials' => new Aws\Credentials\Credentials($this->key, $this->secret), 'version' => 'latest', 'region' => $this->region]); $request = []; # $request['Source'] = urlencode($params['name_from']).'<'.$params['email_from'].'>'; $request['Source'] = $params['email_from']; $request['Destination']['ToAddresses'] = [urlencode($params['name_to']) . ' <' . $params['email_to'] . '>']; # $request['Destination']['ToAddresses'] = [$params['email_to']]; $request['Message']['Subject']['Data'] = $params['subject']; $request['Message']['Body']['Text']['Data'] = $params['text']; $request['Message']['Body']['Html']['Data'] = $params['html']; # TODO 'attachment' $result = $ses->sendEmail($request); $msg_id = $result->get('MessageId'); } catch (Exception $e) { $error_message = 'SES error occurred: ' . get_class($e) . ' - ' . $e->getMessage(); } if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) { trigger_error($error_message, E_USER_WARNING); } if (is_callable($params['on_after_send'])) { $callback = $params['on_after_send']; $callback($mail, $params, $result, $error_message, $this->PARENT); } $this->PARENT->_last_error_message = $error_message; return $result && !$error_message ? true : false; }
public function sesSend() { $awsSettings = array(); $awsSettings['key'] = AMAZON_AWS_KEY; $awsSettings['secret'] = AMAZON_AWS_SECRET; $awsSettings['region'] = AMAZON_AWS_REGION; $ses = Aws\Ses\SesClient::factory($awsSettings); if (defined('SES_USE_DKIM') && SES_USE_DKIM) { $ses->setIdentityDkimEnabled(array('Identity' => EMAIL_USERNAME, 'DkimEnabled' => SES_USE_DKIM)); } //format our from and to emails. //$from = '"' . RR_PROJECT_NAME . '" <' . EMAIL_USERNAME . '>'; if (defined('SES_USE_VERP') && SES_USE_VERP) { $split = explode('@', EMAIL_USERNAME); $from = $split[0] . "+" . $this->get('to_name') . "@" . $split[1]; } else { $from = EMAIL_USERNAME; } $from = '"' . RR_PROJECT_NAME . '" <' . $from . '>'; if ($this->get('to_name')) { $to = '"' . $this->get('to_name') . '" <' . $this->get('to_email') . '>'; } else { $to = $this->get('to_email'); } $response = $ses->sendEmail(array('Source' => $from, 'Destination' => array('ToAddresses' => array($to)), 'Message' => array('Subject' => array('Data' => $this->get('subject'), 'Charset' => 'us-ascii'), 'Body' => array('Text' => array('Data' => $this->get('text_body'), 'Charset' => 'us-ascii'), 'Html' => array('Data' => $this->get('html_body'), 'Charset' => 'us-ascii'))))); return $response->hasKey("ResponseMetadata"); }
protected function __construct() { Yii::import('application.extensions.vendor.autoload', true); $this->emailClient = Aws\Ses\SesClient::factory(array('key' => Yii::app()->params['AmazonSESKey'], 'secret' => Yii::app()->params['AmazonSESSecret'], 'region' => Yii::app()->params['AmazonSESRegion'])); $this->defaultFrom = '*****@*****.**'; }