本文整理汇总了PHP中Cake\Mailer\Email::message方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::message方法的具体用法?PHP Email::message怎么用?PHP Email::message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Mailer\Email
的用法示例。
在下文中一共展示了Email::message方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* 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);
}
示例2: setupEmail
protected function setupEmail(Email $email)
{
$this->sendgridEmail = new \SendGrid\Email();
foreach ($email->to() as $e => $n) {
$this->sendgridEmail->addTo($e, $n);
}
foreach ($email->cc() as $e => $n) {
$this->sendgridEmail->addCc($e, $n);
}
foreach ($email->bcc() as $e => $n) {
$this->sendgridEmail->addBcc($e, $n);
}
foreach ($email->from() as $e => $n) {
$this->sendgridEmail->setFrom($e);
$this->sendgridEmail->setFromName($n);
}
$this->sendgridEmail->setSubject($email->subject());
$this->sendgridEmail->setText($email->message(Email::MESSAGE_TEXT));
$this->sendgridEmail->setHtml($email->message(Email::MESSAGE_HTML));
if ($email->attachments()) {
foreach ($email->attachments() as $attachment) {
$this->sendgridEmail->setAttachment($attachment['file'], $attachment['custom_filename']);
}
}
}
示例3: send
/**
* 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];
}
示例4: send
/**
* Send mail
*
* @param \Cake\Mailer\Email $email Email instance.
* @return array
*/
public function send(Email $email)
{
$this->transportConfig = Hash::merge($this->transportConfig, $this->_config);
$message = ['html' => $email->message(Email::MESSAGE_HTML), 'text' => $email->message(Email::MESSAGE_TEXT), 'subject' => mb_decode_mimeheader($email->subject()), 'from' => key($email->from()), 'fromname' => current($email->from()), 'to' => [], 'toname' => [], 'cc' => [], 'ccname' => [], 'bcc' => [], 'bccname' => [], 'replyto' => array_keys($email->replyTo())[0]];
// Add receipients
foreach (['to', 'cc', 'bcc'] as $type) {
foreach ($email->{$type}() as $mail => $name) {
$message[$type][] = $mail;
$message[$type . 'name'][] = $name;
}
}
// Create a new scoped Http Client
$this->http = new Client(['host' => 'api.sendgrid.com', 'scheme' => 'https', 'headers' => ['User-Agent' => 'CakePHP SendGrid Plugin']]);
$message = $this->_attachments($email, $message);
return $this->_send($message);
}
示例5: send
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];
}
示例6: send
/**
* Send mail via SparkPost REST API
*
* @param \Cake\Mailer\Email $email Email message
* @return array
*/
public function send(Email $email)
{
// Load SparkPost configuration settings
$apiKey = $this->config('apiKey');
// Set up HTTP request adapter
$adapter = new CakeHttpAdapter(new Client());
// Create SparkPost API accessor
$sparkpost = new SparkPost($adapter, ['key' => $apiKey]);
// Pre-process CakePHP email object fields
$from = (array) $email->from();
$sender = sprintf('%s <%s>', mb_encode_mimeheader(array_values($from)[0]), array_keys($from)[0]);
$to = (array) $email->to();
$recipients = [['address' => ['name' => mb_encode_mimeheader(array_values($to)[0]), 'email' => array_keys($to)[0]]]];
// Build message to send
$message = ['from' => $sender, 'html' => empty($email->message('html')) ? $email->message('text') : $email->message('html'), 'text' => $email->message('text'), 'subject' => mb_decode_mimeheader($email->subject()), 'recipients' => $recipients];
// Send message
try {
$sparkpost->transmission->send($message);
} catch (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()));
}
}
示例7: send
/**
* 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];
}
示例8: _prepareMessage
/**
* Prepares the message body.
*
* @param \Cake\Mailer\Email $email Email instance
* @return string
*/
protected function _prepareMessage($email)
{
$lines = $email->message();
$messages = [];
foreach ($lines as $line) {
if (!empty($line) && $line[0] === '.') {
$messages[] = '.' . $line;
} else {
$messages[] = $line;
}
}
return implode("\r\n", $messages);
}