/**
  * Send mail
  *
  * @params CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     $post = array();
     $post_preprocess = array_merge($email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')), array('text' => $email->message(CakeEmail::MESSAGE_TEXT), 'html' => $email->message(CakeEmail::MESSAGE_HTML)));
     foreach ($post_preprocess as $k => $v) {
         if (!empty($v)) {
             $post[strtolower($k)] = $v;
         }
     }
     $ch = curl_init('https://api.mailgun.net/v2/' . $this->_config['mailgun_domain'] . '/messages');
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $this->_config['api_key']);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     $response = curl_exec($ch);
     if ($response === false) {
         throw new SocketException("Curl had an error.  Message: " . curl_error($ch), 500);
     }
     $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($http_status != 200) {
         throw new SocketException("Mailgun request failed.  Status: {$http_status}, Response: {$response}", 500);
     }
     curl_close($ch);
     return array('headers' => $this->_headersToString($email->getHeaders(), PHP_EOL), 'message' => implode(PHP_EOL, $email->message()));
 }
 private function _sendPart()
 {
     if (empty($this->_recipients)) {
         return true;
     }
     $json = array('to' => $this->_getAddress(array_splice($this->_recipients, 0, $this->_config['count'])), 'category' => !empty($this->_headers['X-Category']) ? $this->_headers['X-Category'] : $this->_config['category']);
     //Sendgrid Substitution Tags
     if (!empty($this->_headers['X-Sub'])) {
         foreach ($this->_headers['X-Sub'] as $key => $value) {
             $json['sub'][$key] = array_splice($value, 0, $this->_config['count']);
         }
     }
     $params = array('api_user' => $this->_config['username'], 'api_key' => $this->_config['password'], 'x-smtpapi' => json_encode($json), 'to' => '*****@*****.**', 'subject' => $this->_cakeEmail->subject(), 'html' => $this->_cakeEmail->message('html'), 'text' => $this->_cakeEmail->message('text'), 'from' => $this->_config['from'], 'fromname' => $this->_config['fromName'], 'replyto' => array_keys($this->_replyTo)[0]);
     $attachments = $this->_cakeEmail->attachments();
     if (!empty($attachments)) {
         foreach ($attachments as $key => $value) {
             $params['files[' . $key . ']'] = '@' . $value['file'];
         }
     }
     $result = json_decode($this->_exec($params));
     if ($result->message != 'success') {
         return $result;
     } else {
         return $this->_sendPart();
     }
 }
 /**
  * Send email via Mailgun
  *
  * @param CakeEmail $email
  * @return array
  * @throws Exception
  */
 public function send(CakeEmail $email)
 {
     if (Configure::read('Mailgun.preventManyToRecipients') !== false && count($email->to()) > 1) {
         throw new Exception('More than one "to" recipient not allowed (set Mailgun.preventManyToRecipients = false to disable check)');
     }
     $mgClient = new Mailgun($this->_config['mg_api_key']);
     $headersList = array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject');
     $params = [];
     foreach ($email->getHeaders($headersList) as $header => $value) {
         if (isset($this->_paramMapping[$header]) && !empty($value)) {
             $key = $this->_paramMapping[$header];
             $params[$key] = $value;
         }
     }
     $params['text'] = $email->message(CakeEmail::MESSAGE_TEXT);
     $params['html'] = $email->message(CakeEmail::MESSAGE_HTML);
     $attachments = array();
     foreach ($email->attachments() as $name => $info) {
         $attachments['attachment'][] = '@' . $info['file'];
     }
     try {
         $result = $mgClient->sendMessage($this->_config['mg_domain'], $params, $attachments);
         if ($result->http_response_code != 200) {
             throw new Exception($result->http_response_body->message);
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
 /**
  * Sends out email via Mandrill
  *
  * @param CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $from = $this->_cakeEmail->from();
     list($fromEmail) = array_keys($from);
     $fromName = $from[$fromEmail];
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders();
     $message = array('html' => $this->_cakeEmail->message('html'), 'text' => $this->_cakeEmail->message('text'), 'subject' => mb_decode_mimeheader($this->_cakeEmail->subject()), 'from_email' => $fromEmail, 'from_name' => $fromName, 'to' => array(), 'headers' => array('Reply-To' => $fromEmail), 'important' => false, 'track_opens' => null, 'track_clicks' => null, 'auto_text' => null, 'auto_html' => null, 'inline_css' => null, 'url_strip_qs' => null, 'preserve_recipients' => null, 'view_content_link' => null, 'tracking_domain' => null, 'signing_domain' => null, 'return_path_domain' => null, 'merge' => true, 'tags' => null, 'subaccount' => null);
     $message = array_merge($message, $this->_headers);
     foreach ($this->_cakeEmail->to() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'to');
     }
     foreach ($this->_cakeEmail->cc() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'cc');
     }
     foreach ($this->_cakeEmail->bcc() as $email => $name) {
         $message['to'][] = array('email' => $email, 'name' => $name, 'type' => 'bcc');
     }
     $attachments = $this->_cakeEmail->attachments();
     if (!empty($attachments)) {
         $message['attachments'] = array();
         foreach ($attachments as $file => $data) {
             $message['attachments'][] = array('type' => $data['mimetype'], 'name' => $file, 'content' => base64_encode(file_get_contents($data['file'])));
         }
     }
     $params = array('message' => $message, "async" => false, "ip_pool" => null, "send_at" => null);
     return $this->_exec($params);
 }
 /**
  * Send email via SNS
  * @param CakeEmail $email
  * @return bool
  */
 public function send(CakeEmail $email)
 {
     $ses = SesClient::factory(array("key" => "AKIAIQHPCMQTEEXD5MGA", "secret" => "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", 'region' => 'us-east-1'));
     $destination = array('ToAddresses' => array());
     foreach ($email->to() as $addr => $name) {
         $destination['ToAddresses'][] = "{$name} <{$addr}>";
     }
     foreach ($email->bcc() as $addr => $name) {
         $destination['BccAddresses'][] = "{$name} <{$addr}>";
     }
     $message = array('Subject' => array('Data' => $email->subject()), 'Body' => array());
     $text = $email->message('text');
     if (!empty($text)) {
         $message['Body']['Text'] = array('Data' => $text);
     }
     $html = $email->message('html');
     if (!empty($html)) {
         $message['Body']['Html'] = array('Data' => $html);
     }
     $from = '';
     foreach ($email->from() as $addr => $name) {
         $from = "{$name} <{$addr}>";
         break;
     }
     $response = $ses->sendEmail(['Source' => $from, 'Destination' => $destination, 'Message' => $message]);
     return !empty($response);
 }
 /**
  * Sends out email via SparkPost
  *
  * @param CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // CakeEmail
     $this->_cakeEmail = $email;
     $this->_config = $this->_cakeEmail->config();
     $this->_headers = $this->_cakeEmail->getHeaders();
     // Not allowed by SparkPost
     unset($this->_headers['Content-Type']);
     unset($this->_headers['Content-Transfer-Encoding']);
     unset($this->_headers['MIME-Version']);
     unset($this->_headers['X-Mailer']);
     $from = $this->_cakeEmail->from();
     list($fromEmail) = array_keys($from);
     $fromName = $from[$fromEmail];
     $message = ['html' => $this->_cakeEmail->message('html'), 'text' => $this->_cakeEmail->message('text'), 'from' => ['name' => $fromName, 'email' => $fromEmail], 'subject' => mb_decode_mimeheader($this->_cakeEmail->subject()), 'recipients' => [], 'transactional' => true];
     foreach ($this->_cakeEmail->to() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     foreach ($this->_cakeEmail->cc() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     foreach ($this->_cakeEmail->bcc() as $email => $name) {
         $message['recipients'][] = ['address' => ['email' => $email, 'name' => $name], 'tags' => $this->_headers['tags']];
     }
     unset($this->_headers['tags']);
     $attachments = $this->_cakeEmail->attachments();
     if (!empty($attachments)) {
         $message['attachments'] = array();
         foreach ($attachments as $file => $data) {
             if (!empty($data['contentId'])) {
                 $message['inlineImages'][] = array('type' => $data['mimetype'], 'name' => $data['contentId'], 'data' => base64_encode(file_get_contents($data['file'])));
             } else {
                 $message['attachments'][] = array('type' => $data['mimetype'], 'name' => $file, 'data' => base64_encode(file_get_contents($data['file'])));
             }
         }
     }
     $message = array_merge($message, $this->_headers);
     // Load SparkPost configuration settings
     $config = ['key' => $this->_config['sparkpost']['api_key']];
     if (isset($this->_config['sparkpost']['timeout'])) {
         $config['timeout'] = $this->_config['sparkpost']['timeout'];
     }
     // Set up HTTP request adapter
     $httpAdapter = new Ivory\HttpAdapter\Guzzle6HttpAdapter($this->__getClient());
     // Create SparkPost API accessor
     $sparkpost = new SparkPost\SparkPost($httpAdapter, $config);
     // Send message
     try {
         return $sparkpost->transmission->send($message);
     } catch (SparkPost\APIResponseException $e) {
         // TODO: Determine if BRE is the best exception type
         throw new BadRequestException(sprintf('SparkPost API error %d (%d): %s (%s)', $e->getAPICode(), $e->getCode(), ucfirst($e->getAPIMessage()), $e->getAPIDescription()));
     }
 }
 /**
  * Prepares the data array.
  *
  * @return void 
  */
 protected function _prepareData()
 {
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
     if ($headers['Sender'] == '') {
         $headers['Sender'] = $headers['From'];
     }
     $headers = $this->_headersToString($headers);
     $message = implode("\r\n", $this->_cakeEmail->message());
     $this->_data = array('Data' => base64_encode($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n."));
     $this->_dataOptions = array('Source' => key($this->_cakeEmail->from()), 'Destinations' => array());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->to());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->cc());
     $this->_dataOptions['Destinations'] += array_keys($this->_cakeEmail->bcc());
     $this->_content = array('headers' => $headers, 'message' => $message);
 }
 /**
  * Prepares the data array.
  * Adds headers and content
  *
  * @return void 
  */
 protected function _prepareData()
 {
     $this->_data = array();
     if (count($this->_cakeEmail->cc()) > 0) {
         throw new CakeException('Postageapp transport does not support cc');
     }
     if (count($this->_cakeEmail->bcc()) > 0) {
         throw new CakeException('Postageapp transport does not support bcc');
     }
     if (count($this->_cakeEmail->sender()) > 0) {
         throw new CakeException('Postageapp transport does not support sender');
     }
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'returnPath', 'to', 'subject'));
     $this->_data['recipients'] = $headers['To'];
     $map = array('From', 'Subject', 'Reply-To', 'X-Mailer', 'MIME-Version', 'Content-Transfer-Encoding');
     foreach ($map as $header) {
         if (!empty($headers[$header])) {
             $this->_addHeader($header, $headers[$header]);
         }
     }
     $emailFormat = $this->_cakeEmail->emailFormat();
     if ($emailFormat == 'both' || $emailFormat == 'text') {
         $this->_data['content']['text/plain'] = $this->_cakeEmail->message('text');
     }
     if ($emailFormat == 'both' || $emailFormat == 'html') {
         $this->_data['content']['text/html'] = $this->_cakeEmail->message('html');
     }
 }
Esempio n. 9
0
 /**
  * Build message
  *
  * @return array
  */
 private function __buildMessage()
 {
     // Message
     $message = array();
     // From
     $message['From'] = $this->_headers['From'];
     // To
     $message['To'] = $this->_headers['To'];
     // Cc
     $message['Cc'] = $this->_headers['Cc'];
     // Bcc
     $message['Bcc'] = $this->_headers['Bcc'];
     // ReplyTo
     $message['ReplyTo'] = $this->_headers['Reply-To'];
     // Subject
     $message['Subject'] = iconv_mime_decode($this->_headers['Subject']);
     // Tag
     if (isset($this->_headers['Tag'])) {
         $message['Tag'] = $this->_headers['Tag'];
     }
     // HtmlBody
     if ($this->_cakeEmail->emailFormat() === 'html' || $this->_cakeEmail->emailFormat() === 'both') {
         $message['HtmlBody'] = $this->_cakeEmail->message('html');
     }
     // TextBody
     if ($this->_cakeEmail->emailFormat() === 'text' || $this->_cakeEmail->emailFormat() === 'both') {
         $message['TextBody'] = $this->_cakeEmail->message('text');
     }
     // Attachments
     $message['Attachments'] = $this->__buildAttachments();
     return $message;
 }
Esempio n. 10
0
 /**
  * Send mail
  *
  * @param CakeEmail $email CakeEmail
  * @return array
  */
 public function send(CakeEmail $email)
 {
     $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
     $headers = $this->_headersToString($headers);
     $message = implode("\r\n", (array) $email->message());
     return array('headers' => $headers, 'message' => $message);
 }
Esempio n. 11
0
 /**
  * Send Data
  *
  * @return void
  * @throws SocketException
  */
 protected function _sendData()
 {
     $this->_smtpSend('DATA', '354');
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
     $headers = $this->_headersToString($headers);
     $message = implode("\r\n", $this->_cakeEmail->message());
     $this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
     $this->_content = array('headers' => $headers, 'message' => $message);
 }
 /**
  * Send
  * 
  * A bit of a misnomer, because this actually just adds it to a CakeResque
  * queue.  The actual sending of the email will be performed later by a worker.
  *
  * @params CakeEmail $email
  * @return array
  */
 public function send(CakeEmail $email)
 {
     // Take a copy of the existing configuration.
     $config = array('headers' => $email->getHeaders(), 'from' => $email->from(), 'sender' => $email->sender(), 'replyTo' => $email->replyTo(), 'readReceipt' => $email->readReceipt(), 'returnPath' => $email->returnPath(), 'to' => $email->to(), 'cc' => $email->cc(), 'bcc' => $email->bcc(), 'subject' => $email->subject(), 'viewRender' => $email->viewRender(), 'viewVars' => $email->viewVars(), 'emailFormat' => $email->emailFormat(), 'messageId' => $email->messageId(), 'attachments' => $email->attachments());
     //        unset($config['config']['transport']);
     $template = $email->template();
     $config['template'] = $template['template'];
     $config['layout'] = $template['layout'];
     // Clean it up to avoid errors.
     $config = array_filter($config, function ($v) {
         return (bool) $v;
     });
     debug($config);
     // Include a message, if they sent one via plain text.
     $message = $email->message(CakeEmail::MESSAGE_HTML) ? null : $email->message(CakeEmail::MESSAGE_TEXT);
     // Drop it in a queue.
     Resque::enqueue('email', 'ResqueEmail.EmailShell', array('send', $config, $message));
     return array('headers' => $email->getHeaders(), 'message' => $email->message());
 }
Esempio n. 13
0
 /**
  * Build message
  *
  * @return array
  */
 private function __buildMessage()
 {
     // Message
     $json = array();
     $json["key"] = $this->_config['key'];
     $message = array();
     // From
     $fromEmail = $this->_cakeEmail->from();
     reset($fromEmail);
     $message['from_email'] = key($fromEmail);
     if ($message['from_email'] != current($fromEmail)) {
         $message['from_name'] = current($fromEmail);
     }
     // To
     $message["to"] = array(array("email" => $this->_headers['To']));
     // Subject
     $message['subject'] = mb_decode_mimeheader($this->_headers['Subject']);
     //Template Name
     if (isset($this->_config['mandrillTemplate']) && !empty($this->_config['mandrillTemplate'])) {
         $json['template_name'] = $this->_config['mandrillTemplate'];
         $json['template_content'] = '';
         //Template Variables -> Merge Variables in Mandrill
         $vars = $this->_cakeEmail->viewVars();
         if (!empty($vars)) {
             $message['global_merge_vars'] = array();
             foreach ($vars as $key => $var) {
                 $message['global_merge_vars'][] = array('name' => $key, 'content' => $var);
             }
         }
     }
     // HtmlBody
     if ($this->_cakeEmail->emailFormat() === 'html' || $this->_cakeEmail->emailFormat() === 'both') {
         $message['html'] = $this->_cakeEmail->message('html');
     }
     // TextBody
     if ($this->_cakeEmail->emailFormat() === 'text' || $this->_cakeEmail->emailFormat() === 'both') {
         $message['text'] = $this->_cakeEmail->message('text');
     }
     $attachments = $this->_cakeEmail->attachments();
     $messageAttachments = array();
     if (!empty($attachments)) {
         foreach ($attachments as $key => $attachment) {
             $content = file_get_contents($attachment['file']);
             $content = base64_encode($content);
             $messageAttachments[] = array('type' => $attachment['mimetype'], 'name' => $key, 'content' => $content);
         }
         if (!empty($messageAttachments)) {
             $message['attachments'] = $messageAttachments;
         }
     }
     $json["message"] = $message;
     return $json;
 }
 /**
  * Send
  *
  * @param CakeEmail $email objeto mail
  * @return array
  * @throws SocketException
  */
 public function send(CakeEmail $email)
 {
     $http = new HttpSocket();
     $url = 'https://api.mailgun.net/v2/' . $this->_config['mailgun_domain'] . '/messages';
     $post = array();
     $postPreprocess = array_merge($email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')), array('text' => $email->message(CakeEmail::MESSAGE_TEXT), 'html' => $email->message(CakeEmail::MESSAGE_HTML)));
     foreach ($postPreprocess as $k => $v) {
         if (!empty($v)) {
             $post[strtolower($k)] = $v;
         }
     }
     $request = array('auth' => array('method' => 'Basic', 'user' => 'api', 'pass' => $this->_config['api_key']));
     $response = $http->post($url, $post, $request);
     if ($response === false) {
         throw new SocketException("Mailgun BasicTransport error, no response", 500);
     }
     $httpStatus = $response->code;
     if ($httpStatus != 200) {
         throw new SocketException("Mailgun request failed.  Status: {$httpStatus}, Response: {$response->body}", 500);
     }
     return array('headers' => $this->_headersToString($email->getHeaders(), PHP_EOL), 'message' => implode(PHP_EOL, $email->message()));
 }
 /**
  * Prepares the message body.
  *
  * @return string
  */
 protected function _prepareMessage()
 {
     $lines = $this->_cakeEmail->message();
     $messages = array();
     foreach ($lines as $line) {
         if (!empty($line) && $line[0] === '.') {
             $messages[] = '.' . $line;
         } else {
             $messages[] = $line;
         }
     }
     return implode("\r\n", $messages);
 }
Esempio n. 16
0
 /**
  * Send mail
  *
  * @param CakeEmail $email CakeEmail
  * @return array
  * @throws SocketException When mail cannot be sent.
  */
 public function send(CakeEmail $email)
 {
     $eol = PHP_EOL;
     if (isset($this->_config['eol'])) {
         $eol = $this->_config['eol'];
     }
     $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
     $to = $headers['To'];
     unset($headers['To']);
     $headers = $this->_headersToString($headers, $eol);
     $message = implode($eol, $email->message());
     $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
     $this->_mail($to, $email->subject(), $message, $headers, $params);
     return array('headers' => $headers, 'message' => $message);
 }
Esempio n. 17
0
 /**
  * Send mail
  *
  * @params object $email CakeEmail
  * @return boolean
  */
 public function send(CakeEmail $email)
 {
     $eol = PHP_EOL;
     if (isset($this->_config['eol'])) {
         $eol = $this->_config['eol'];
     }
     $headers = $email->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
     $to = $headers['To'];
     unset($headers['To']);
     $header = $this->_headersToString($headers, $eol);
     $message = implode($eol, $email->message());
     if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
         return @mail($to, $email->subject(), $message, $header);
     }
     return @mail($to, $email->subject(), $message, $header, $this->_config['additionalParameters']);
 }
Esempio n. 18
0
 /**
  * Send mail
  *
  * @params object $email CakeEmail
  * @return boolean
  */
 public function send(CakeEmail $email)
 {
     $headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
     $to = $headers['To'];
     $subject = $headers['Subject'];
     unset($headers['To'], $headers['Subject']);
     $message = implode("\n", $email->message());
     $last = '<pre>';
     $last .= sprintf("%s %s\n", 'To:', $to);
     $last .= sprintf("%s %s\n", 'From:', $headers['From']);
     $last .= sprintf("%s %s\n", 'Subject:', $subject);
     $last .= sprintf("%s\n\n%s", 'Header:', $this->_headersToString($headers, "\n"));
     $last .= sprintf("%s\n\n%s", 'Message:', $message);
     $last .= '</pre>';
     self::$lastEmail = $last;
     return true;
 }
Esempio n. 19
0
 /**
  * Send Data
  *
  * @return void
  * @throws SocketException
  */
 protected function _sendData()
 {
     $this->_smtpSend('DATA', '354');
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
     $headers = $this->_headersToString($headers);
     $lines = $this->_cakeEmail->message();
     $messages = array();
     foreach ($lines as $line) {
         if (!empty($line) && $line[0] === '.') {
             $messages[] = '.' . $line;
         } else {
             $messages[] = $line;
         }
     }
     $message = implode("\r\n", $messages);
     $this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
     $this->_content = array('headers' => $headers, 'message' => $message);
 }
Esempio n. 20
0
 /**
  * Send mail
  *
  * @param CakeEmail $email CakeEmail
  *
  * @return array
  * @throws SocketException When mail cannot be sent.
  */
 public function send(CakeEmail $email)
 {
     $eol = PHP_EOL;
     if (isset($this->_config['eol'])) {
         $eol = $this->_config['eol'];
     }
     $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
     $to = $headers['To'];
     unset($headers['To']);
     foreach ($headers as $key => $header) {
         $headers[$key] = str_replace(array("\r", "\n"), '', $header);
     }
     $headers = $this->_headersToString($headers, $eol);
     $subject = str_replace(array("\r", "\n"), '', $email->subject());
     $to = str_replace(array("\r", "\n"), '', $to);
     $message = implode($eol, $email->message());
     $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : NULL;
     $this->_mail($to, $subject, $message, $headers, $params);
     return array('headers' => $headers, 'message' => $message);
 }
 /**
  * Send mail
  *
  * @param CakeEmail $email CakeEmail
  * @return array
  * @throws SocketException When mail cannot be sent.
  */
 public function send(CakeEmail $email)
 {
     $eol = PHP_EOL;
     if (isset($this->_config['eol'])) {
         $eol = $this->_config['eol'];
     }
     $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
     $to = $headers['To'];
     unset($headers['To']);
     $headers = $this->_headersToString($headers, $eol);
     $message = implode($eol, $email->message());
     if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
         if (!@mail($to, $email->subject(), $message, $headers)) {
             throw new SocketException(__d('cake_dev', 'Could not send email.'));
         }
     } elseif (!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) {
         throw new SocketException(__d('cake_dev', 'Could not send email.'));
     }
     return array('headers' => $headers, 'message' => $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);
 }
 /**
  * Prepares the data array.
  * Adds headers and content
  *
  * @return void 
  */
 protected function _prepareData()
 {
     $this->_data = array();
     $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'returnPath', 'to', 'cc', 'bcc', 'subject'));
     $map = array('From', 'To', 'Cc', 'Bcc', 'Subject');
     foreach ($map as $header) {
         if (!empty($headers[$header])) {
             $this->_data[$header] = $headers[$header];
         }
     }
     if (!empty($headers['Reply-To'])) {
         $this->_data['ReplyTo'] = $headers['Reply-To'];
     }
     $tag = false;
     if (isset($headers['X-Tag'])) {
         $tag = $headers['X-Tag'];
     } elseif (isset($this->_config['tag'])) {
         $tag = $this->_config['tag'];
     }
     if ($tag !== false) {
         $this->_data['Tag'] = $this->_config['tag'];
     }
     $map = array('X-Mailer', 'MIME-Version', 'Content-Transfer-Encoding');
     foreach ($map as $header) {
         if (!empty($headers[$header])) {
             $this->_addHeader($header, $headers[$header]);
         }
     }
     $emailFormat = $this->_cakeEmail->emailFormat();
     if ($emailFormat == 'both' || $emailFormat == 'text') {
         $this->_data['TextBody'] = $this->_cakeEmail->message('text');
     }
     if ($emailFormat == 'both' || $emailFormat == 'html') {
         $this->_data['HtmlBody'] = $this->_cakeEmail->message('html');
     }
 }
Esempio n. 24
0
 /**
  * Send mail
  *
  * @params object $email CakeEmail
  * @return boolean
  */
 public function send(CakeEmail $email)
 {
     $headers = $email->getHeaders(array('from' => true, 'sender' => true, 'replyTo' => true, 'readReceipt' => true, 'returnPath' => true, 'to' => true, 'cc' => true, 'bcc' => true, 'subject' => true));
     $headers = $this->_headersToString($headers);
     return $headers . "\n\n" . implode((array) $email->message(), "\n");
 }
Esempio n. 25
0
 public function send_email($dest = null)
 {
     $Email = new CakeEmail('gmail');
     $Email->to($dest);
     $Email->subject('Automagically generated email');
     $Email->replyTo('*****@*****.**');
     $Email->message('teste');
     $Email->from('*****@*****.**');
     $Email->send();
     return $this->redirect(array('action' => 'index'));
 }
Esempio n. 26
0
/**
 * Send an email using the specified content, template and layout
 *
 * @param string|array $content Either an array of text lines, or a string with contents
 *  If you are rendering a template this variable will be sent to the templates as `$content`
 * @param string $template Template to use when sending email
 * @param string $layout Layout to use to enclose email body
 * @return boolean Success
 */
	public function send($content = null, $template = null, $layout = null) {
		$lib = new CakeEmail();
		$lib->charset = $this->charset;
		$lib->headerCharset = $this->charset;

		$lib->from($this->_formatAddresses((array)$this->from));
		if (!empty($this->to)) {
			$lib->to($this->_formatAddresses((array)$this->to));
		}
		if (!empty($this->cc)) {
			$lib->cc($this->_formatAddresses((array)$this->cc));
		}
		if (!empty($this->bcc)) {
			$lib->bcc($this->_formatAddresses((array)$this->bcc));
		}
		if (!empty($this->replyTo)) {
			$lib->replyTo($this->_formatAddresses((array)$this->replyTo));
		}
		if (!empty($this->return)) {
			$lib->returnPath($this->_formatAddresses((array)$this->return));
		}
		if (!empty($this->readReceipt)) {
			$lib->readReceipt($this->_formatAddresses((array)$this->readReceipt));
		}

		$lib->subject($this->subject)->messageID($this->messageId);
		$lib->helpers($this->_controller->helpers);

		$headers = array('X-Mailer' => $this->xMailer);
		foreach ($this->headers as $key => $value) {
			$headers['X-' . $key] = $value;
		}
		if ($this->date) {
			$headers['Date'] = $this->date;
		}
		$lib->setHeaders($headers);

		if ($template) {
			$this->template = $template;
		}
		if ($layout) {
			$this->layout = $layout;
		}
		$lib->template($this->template, $this->layout)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs);

		if (!empty($this->attachments)) {
			$lib->attachments($this->_formatAttachFiles());
		}

		$lib->transport(ucfirst($this->delivery));
		if ($this->delivery === 'mail') {
			$lib->config(array('eol' => $this->lineFeed, 'additionalParameters' => $this->additionalParams));
		} elseif ($this->delivery === 'smtp') {
			$lib->config($this->smtpOptions);
		} else {
			$lib->config(array());
		}

		$sent = $lib->send($content);

		$this->htmlMessage = $lib->message(CakeEmail::MESSAGE_HTML);
		if (empty($this->htmlMessage)) {
			$this->htmlMessage = null;
		}
		$this->textMessage = $lib->message(CakeEmail::MESSAGE_TEXT);
		if (empty($this->textMessage)) {
			$this->textMessage = null;
		}

		$this->_header = array();
		$this->_message = array();

		return $sent;
	}
Esempio n. 27
0
 /**
  * Send
  *
  * @param object $email CakeEmail
  * @return boolean
  */
 public function send(CakeEmail $email)
 {
     self::$lastEmail = implode("\r\n", $email->message());
     $options = array();
     if (self::$includeAddresses) {
         $options = array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true);
     }
     self::$lastHeader = $this->_headersToString($email->getHeaders($options));
     return true;
 }