/** * Sends mail using Amazon SES. * @param string $header The message headers * @param string $body The message body * @access protected * @return bool */ protected function AmazonSESSend($header, $body) { //$ses = @new AmazonSES($this->AWSAccessKeyID, $this->AWSSecretKey); $ses = new AmazonSES(array("key" => $this->AWSAccessKeyID, "secret" => $this->AWSSecretKey)); if ($this->SingleTo === true) { foreach ($this->SingleToArray as $key => $val) { $response = $ses->send_raw_email(array('Data' => base64_encode($header . "\n" . $body)), array('Source' => $this->From, 'Destinations' => $val)); // implement call back function if it exists $isSent = $response->isOK() ? 1 : 0; $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); if (!$isSent) { throw new phpmailerException('Error Sending via Amazon SES', self::STOP_CRITICAL); } } } else { $response = $ses->send_raw_email(array('Data' => base64_encode($header . "\n" . $body)), array('Source' => $this->From, 'Destinations' => $this->to)); // implement call back function if it exists $isSent = $response->isOK() ? 1 : 0; $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body); if (!$isSent) { throw new phpmailerException('Error Sending via Amazon SES', self::STOP_CRITICAL); } } return true; }
/** * Posts the data to the postmark API endpoint * * @return array * @throws CakeException */ protected function _amazonSend() { $this->_generateAmazonSes(); $response = $this->_amazonSes->send_raw_email($this->_data, $this->_dataOptions); if (!$response->isOK()) { throw new CakeException((string) $response->body->Error->Message); } }
/** * Send mail * * @param CakeEmail $email CakeEmail * @return array * @throws SocketException When mail cannot be sent. */ public function send(CakeEmail $email) { App::import('Vendor', 'Amazon', array('file' => 'AWSSDKforPHP/sdk.class.php')); $init_options['key'] = $this->_config['Amazon.SES.Key']; $init_options['secret'] = $this->_config['Amazon.SES.Secret']; $ses = new AmazonSES($init_options); $eol = PHP_EOL; if (isset($this->_config['eol'])) { $eol = $this->_config['eol']; } $option = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : array(); $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject')); $headers = $this->_headersToString($headers); $message = implode($eol, (array) $email->message()); $raw_message = $headers . $eol . $eol . $message; $res = $ses->send_raw_email(array('Data' => base64_encode($raw_message)), $option); if ($res->status != 200) { CakeLog::write('error', var_export($res, 1)); throw new SocketException(__d('cake_dev', 'Could not send email.')); } return array('headers' => $headers, 'message' => $message); }