/** * Send email via Mailgun SDK * * @param Email $email * @return \stdClass $result containing status code and message * @throws Exception */ public function send(Email $email) { $config = $email->profile(); $email->domain($config['mailgun_domain']); $emailHeaders = ['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject', '_headers']; //'_headers' will include all extra tags that may be related to mailgun fields with prefix 'o:' or custom data with prefix 'v:' foreach ($email->getHeaders($emailHeaders) as $header => $value) { if (isset($this->ParamMapping[$header]) && !empty($value)) { //empty params are not excepted by mailgun, throws error $key = $this->ParamMapping[$header]; $params[$key] = $value; continue; } if ($this->isDataCustom($header, $value)) { $params[$header] = $value; } } $params['html'] = $email->message(Email::MESSAGE_HTML); $params['text'] = $email->message(Email::MESSAGE_TEXT); $attachments = array(); foreach ($email->attachments() as $name => $file) { $attachments['attachment'][] = ['filePath' => '@' . $file['file'], 'remoteName' => $name]; } return $this->mailgun($config, $params, $attachments); }
/** * Send mail * * @param \Cake\Mailer\Email $email Cake Email * @return array */ public function send(Email $email) { $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject']); $headers = $this->_headersToString($headers); $message = implode("\r\n", (array) $email->message()); return ['headers' => $headers, 'message' => $message]; }
public function send(Email $email) { $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']); $to = $headers['To']; $subject = str_replace(["\r", "\n"], '', $email->subject()); $to = str_replace(["\r", "\n"], '', $to); $message = implode('\\n', $email->message()); Log::write('debug', 'Mail: to(' . $to . ') subject(' . $subject . ') message(' . $message . ')'); return ['headers' => $headers, 'message' => $message]; }
/** * Send mail * * @param \Cake\Mailer\Email $email Email * @return array */ public function send(Email $email) { if (!empty($this->_config['queue'])) { $this->_config = $this->_config['queue'] + $this->_config; $email->config((array) $this->_config['queue'] + ['queue' => []]); unset($this->_config['queue']); } $settings = ['from' => [$email->from()], 'to' => [$email->to()], 'cc' => [$email->cc()], 'bcc' => [$email->bcc()], 'charset' => [$email->charset()], 'replyTo' => [$email->replyTo()], 'readReceipt' => [$email->readReceipt()], 'returnPath' => [$email->returnPath()], 'messageId' => [$email->messageId()], 'domain' => [$email->domain()], 'getHeaders' => [$email->getHeaders()], 'headerCharset' => [$email->headerCharset()], 'theme' => [$email->theme()], 'profile' => [$email->profile()], 'emailFormat' => [$email->emailFormat()], 'subject' => method_exists($email, 'getOriginalSubject') ? [$email->getOriginalSubject()] : [$email->subject()], 'transport' => [$this->_config['transport']], 'attachments' => [$email->attachments()], 'template' => $email->template(), 'viewVars' => [$email->viewVars()]]; foreach ($settings as $setting => $value) { if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { unset($settings[$setting]); } } $QueuedJobs = $this->getQueuedJobsModel(); $result = $QueuedJobs->createJob('Email', ['settings' => $settings]); $result['headers'] = ''; $result['message'] = ''; return $result; }
/** * Send mail * * @param \Cake\Mailer\Email $email Cake Email * @return array */ public function send(Email $email) { $eol = PHP_EOL; if (isset($this->_config['eol'])) { $eol = $this->_config['eol']; } $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']); $to = $headers['To']; unset($headers['To']); foreach ($headers as $key => $header) { $headers[$key] = str_replace(["\r", "\n"], '', $header); } $headers = $this->_headersToString($headers, $eol); $subject = str_replace(["\r", "\n"], '', $email->subject()); $to = str_replace(["\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 ['headers' => $headers, 'message' => $message]; }
/** * Prepares the message headers. * * @param \Cake\Mailer\Email $email Email instance * @return array */ protected function _prepareMessageHeaders($email) { return $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'to', 'cc', 'subject', 'returnPath']); }
/** * Tests that the body is encoded using the configured charset (Japanese irregular encoding, but sometime use this) * * @return void */ public function testBodyEncodingIso2022JpMs() { $email = new Email(['charset' => 'iso-2022-jp-ms', 'headerCharset' => 'iso-2022-jp-ms', 'transport' => 'debug']); $email->subject('あれ?もしかしての前と'); $headers = $email->getHeaders(['subject']); $expected = "?ISO-2022-JP?B?GyRCJCIkbCEpJGIkNyQrJDckRiROQTAkSBsoQg==?="; $this->assertContains($expected, $headers['Subject']); $email->to('*****@*****.**')->from('*****@*****.**'); $result = $email->send('①㈱'); $this->assertTextContains("Content-Type: text/plain; charset=ISO-2022-JP", $result['headers']); $this->assertTextNotContains("Content-Type: text/plain; charset=iso-2022-jp-ms", $result['headers']); // not charset=iso-2022-jp-ms $this->assertContains(mb_convert_encoding('①㈱', 'ISO-2022-JP-MS'), $result['message']); }