本文整理汇总了PHP中CakeEmail::attachments方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeEmail::attachments方法的具体用法?PHP CakeEmail::attachments怎么用?PHP CakeEmail::attachments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeEmail
的用法示例。
在下文中一共展示了CakeEmail::attachments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* 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);
}
示例2: _sendPart
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' => 'example3@sendgrid.com', '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();
}
}
示例3: send
/**
* 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()));
}
}
示例4: _sendMails
public function _sendMails($to, $sub = '', $contents = '', $attachments = null, $cc = null, $bcc = null)
{
//prd($contents);
if (empty($from)) {
$from = strtolower(Configure::read('Site.email'));
}
$Email = new CakeEmail();
$Email->config('smtp');
$Email->emailFormat('html');
$Email->subject($sub);
$Email->template('default', 'default');
$Email->to($to);
$Email->from(array($from => $sub));
$Email->replyTo('mail-noreply@meocart.com', "Meocart Team");
if (!empty($cc)) {
$Email->cc($cc);
}
if (!empty($bcc)) {
$Email->bcc($bcc);
}
if (!empty($attachments) && $attachments != '' && is_array($attachments)) {
$Email->attachments($attachments);
}
$Email->viewVars(array('content' => $contents));
try {
if ($Email->send()) {
return true;
}
return false;
} catch (Exception $e) {
return $e->getMessage();
}
}
示例5: contact
public function contact()
{
$this->loadModel('Contact');
if ($this->request->is('post')) {
$this->Contact->set($this->request->data);
if ($this->Contact->validates()) {
App::uses('CakeEmail', 'Network/Email');
if ($this->request->data['Contact']['subject'] == '') {
$this->request->data['Contact']['subject'] = 'Contact';
}
$Email = new CakeEmail('smtp');
$Email->viewVars(array('mailData' => $this->request->data));
$Email->template('contact', 'default');
$Email->emailFormat('html');
$Email->from(array($this->request->data['Contact']['mail'] => $this->request->data['Contact']['name']));
$Email->to('contact@youthbook.be');
$Email->subject($this->request->data['Contact']['subject']);
$Email->attachments(array('logo.png' => array('file' => WWW_ROOT . '/img/icons/logo.png', 'mimetype' => 'image/png', 'contentId' => 'logo')));
$Email->send();
$this->Flash->success(__('Votre mail a bien été envoyé.'));
return $this->redirect($this->referer());
} else {
$this->Session->write('errors.Contact', $this->Contact->validationErrors);
$this->Session->write('data', $this->request->data);
$this->Session->write('flash', 'Le mail n’a pas pu être envoyé. Veuillez réessayer SVP.');
return $this->redirect($this->referer());
}
}
}
示例6: send
/**
* 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;
}
示例7: send
/**
* Send
*
* @param CakeEmail $email objeto mail
* @return array
* @throws SocketException
*/
public function send(CakeEmail $email)
{
$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;
}
}
if ($attachments = $email->attachments()) {
$i = 1;
foreach ($attachments as $attachment) {
$post['attachment[' . $i . ']'] = "@" . $attachment["file"];
$i++;
}
}
$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);
}
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpStatus != 200) {
throw new SocketException("Mailgun request failed. Status: {$httpStatus}, Response: {$response}", 500);
}
curl_close($ch);
return array('headers' => $this->_headersToString($email->getHeaders(), PHP_EOL), 'message' => implode(PHP_EOL, $email->message()));
}
示例8: addAttachments
protected function addAttachments(CakeEmail $email)
{
$attachments = $email->attachments();
$this->data['attachments'] = array();
foreach ($attachments as $filename => $data) {
$this->data['attachments'][] = array('filename' => $filename, 'content' => file_get_contents($data['file']));
}
}
示例9: testPostmarkSend
/**
* testPostmarkSend method
*
* @return void
*/
public function testPostmarkSend()
{
$this->email->config('postmark');
$this->email->template('default', 'default');
$this->email->emailFormat('html');
$this->email->from(array('yourpostmark@mail.com' => 'Your Name'));
$this->email->to(array('recipient@domain.com' => 'Recipient'));
$this->email->cc(array('recipient@domain.com' => 'Recipient'));
$this->email->bcc(array('recipient@domain.com' => 'Recipient'));
$this->email->subject('Test Postmark');
$this->email->addHeaders(array('Tag' => 'my tag'));
$this->email->attachments(array('cake.icon.png' => array('file' => WWW_ROOT . 'img' . DS . 'cake.icon.png')));
$sendReturn = $this->email->send();
$headers = $this->email->getHeaders(array('to'));
$this->assertEqual($sendReturn['To'], $headers['To']);
$this->assertEqual($sendReturn['ErrorCode'], 0);
$this->assertEqual($sendReturn['Message'], 'OK');
}
示例10: _prepareAttachments
/**
* Reads attached files and adds them to the data
*
* @return void
*/
protected function _prepareAttachments()
{
$attachments = $this->_cakeEmail->attachments();
if (empty($attachments)) {
return;
}
foreach ($attachments as $filename => $info) {
$content = $this->_readFile($info['file']);
$this->_data['attachments'][$filename] = array('content' => $content, 'Content_type' => $info['mimetype']);
}
}
示例11: __buildMessage
/**
* 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;
}
示例12: __buildAttachments
/**
* Build attachments
*
* @return array
*/
private function __buildAttachments()
{
// Attachments
$attachments = array();
$i = 0;
foreach ($this->_cakeEmail->attachments() as $fileName => $fileInfo) {
$handle = fopen($fileInfo['file'], 'rb');
$data = fread($handle, filesize($fileInfo['file']));
$data = chunk_split(base64_encode($data));
fclose($handle);
$attachments[$i]['Name'] = $fileName;
$attachments[$i]['Content'] = $data;
$attachments[$i]['ContentType'] = $fileInfo['mimetype'];
$i++;
}
return $attachments;
}
示例13: send
/**
* 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());
}
示例14: sendMail
/**
* Sends an email
* @param array $email_data Email data
* @param array $attachments Attachments data
* @return boolean Success of operation
*/
public function sendMail($email_data = array(), $attachments = null)
{
$Email = new CakeEmail();
$Email->config($email_data['config']);
$Email->to($email_data['to']);
if (!is_null($email_data['cc'])) {
$Email->cc($email_data['cc']);
}
$Email->subject($email_data['subject']);
$Email->emailFormat('html');
$Email->template($email_data['template'], $email_data['layout']);
$Email->viewvars($email_data['viewvars']);
if (!is_null($attachments)) {
$Email->attachments($attachments);
}
if ($Email->send()) {
return true;
}
}
示例15: sendBill
/**
* @param $order
* @param $to
* @param $filename
*/
public function sendBill($order, $to, $filename)
{
$Email = new CakeEmail('gmail');
$Email->emailFormat('html');
$Email->template('order_details_mail')->viewVars(array('order' => $order));
$Email->to($to);
$Email->subject('Receipt - MadDollTees');
$Email->replyTo('maddolltees@gmail.com');
$Email->from('maddolltees@gmail.com');
$Email->attachments('../webroot/pdf/' . $filename . '.pdf');
$Email->send();
$Email = new CakeEmail('gmail');
$Email->emailFormat('html');
$Email->template('order_details_to_admin')->viewVars(array('order' => $order));
$Email->to('maddolltees@gmail.com');
$Email->subject('Receipt - MadDollTees');
$Email->replyTo('maddolltees@gmail.com');
$Email->from('maddolltees@gmail.com');
$Email->attachments('../webroot/pdf/' . $filename . '.pdf');
$Email->send();
}