/** * 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); }
/** * 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'); } }
/** * 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())); } }
/** * Saves a lead into the leads table * @param array $data * @param string $type The lead type - usually the page type * @return boolean */ public function saveLead($data = array(), $type = null) { if (!$data || !$type) { throw new NotFoundException(__('Invalid data or type')); } $data['Lead']['type'] = $type; $this->create(); $result = $this->save($data); if (!$result) { throw new LogicException(__('There was a problem, please review the errors below and try again.')); } $this->Setting = ClassRegistry::init('Setting'); $siteEmail = $this->Setting->get('siteEmail'); $siteName = $this->Setting->get('siteName'); $ccEmails = $this->Setting->get('siteEmailsCc'); if ($siteEmail) { App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail(); $email->from(array($result['Lead']['email'] => $result['Lead']['name'])); $email->to($siteEmail); if ($ccEmails) { $email->cc($ccEmails); } $email->subject(__('%s - The %s form has been submitted', $siteName, $result['Lead']['type'])); $email->template('newLead'); $email->emailFormat('both'); $email->viewVars(array('lead' => $result, 'siteName' => $siteName)); $email->send(); } return true; }
public function sendEmail($to = NULL, $subject = NULL, $data = NULL, $template = NULL, $format = 'text', $cc = NULL, $bcc = NULL) { $Email = new CakeEmail(); $Email->from(array(Configure::read('Email_From_Email') => Configure::read('Email_From_Name'))); //$Email->config(Configure::read('TRANSPORT')); $Email->config('default'); $Email->template($template); if ($to != NULL) { $Email->to($to); } if ($cc != NULL) { $Email->cc($cc); } if ($bcc != NULL) { $Email->bcc($bcc); } $Email->subject($subject); $Email->viewVars($data); $Email->emailFormat($format); if ($Email->send()) { return true; } else { return false; } }
public function SendQueryMail($userData, $productData) { $sendArr = array(); $sendArr['Name'] = $userData['name']; $sendArr['chef'] = $productData['User']['first_name']; $sendArr['phone'] = $userData['phone']; $sendArr['query'] = $userData['query']; $sendArr['useremail'] = base64_decode($userData['email']); $sendArr['queryfor'] = $userData['queryfor']; $sendArr['product'] = $productData['Product']['name']; $sendArr['price'] = $productData['Product']['price']; $sendArr['orderby'] = $userData['orderBy']; $sendArr['pick'] = $userData['pickupBy']; $sendmail = array($productData['User']['email'], base64_decode($userData['email'])); $email = new CakeEmail('smtp'); $email->from(array('*****@*****.**' => 'YumPlate Support')); $email->sender('*****@*****.**'); $email->cc(Configure::read('Settings.SUPPORT_EMAIL')); $email->to($sendmail); //$email->to('*****@*****.**'); $email->template('askmail'); $email->emailFormat('html'); $email->viewVars(array('sendArr' => $sendArr)); $email->subject('Ask the Cook'); $body = " "; try { $result = $email->send(); } catch (Exception $ex) { //pr($ex);die; // we could not send the email, ignore it return false; } return true; }
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('*****@*****.**', "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(); } }
/** * Prepares the recipient email addresses. * * @return array */ protected function _prepareRecipientAddresses() { $to = $this->_cakeEmail->to(); $cc = $this->_cakeEmail->cc(); $bcc = $this->_cakeEmail->bcc(); return array_merge(array_keys($to), array_keys($cc), array_keys($bcc)); }
/** * testPostmarkSend method * * @return void */ public function testPostmarkSend() { $this->email->config('postmark'); $this->email->template('default', 'default'); $this->email->emailFormat('html'); $this->email->from(array('*****@*****.**' => 'Your Name')); $this->email->to(array('*****@*****.**' => 'Recipient')); $this->email->cc(array('*****@*****.**' => 'Recipient')); $this->email->bcc(array('*****@*****.**' => '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'); }
/** * Send emails * * @return void * @throws SocketException */ protected function _sendRcpt() { $from = $this->_cakeEmail->from(); $this->_smtpSend('MAIL FROM:<' . key($from) . '>'); $to = $this->_cakeEmail->to(); $cc = $this->_cakeEmail->cc(); $bcc = $this->_cakeEmail->bcc(); $emails = array_merge(array_keys($to), array_keys($cc), array_keys($bcc)); foreach ($emails as $email) { $this->_smtpSend('RCPT TO:<' . $email . '>'); } }
/** * 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); }
/** * 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()); }
/** * 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; } }
protected function buildRequest(CakeEmail $email) { $sender = $email->from(); if (key($sender) != '*****@*****.**') { $this->data['fromEmail'] = key($sender); $this->data['fromName'] = reset($sender); } $replyTo = $email->replyTo(); if (!empty($replyTo)) { $this->data['replyToEmail'] = key($replyTo); $this->data['replyToName'] = reset($replyTo); } $headers = $email->getHeaders(array('subject', 'id', 'language')); if (empty($headers['id'])) { throw new CakeException("ID header is required"); } $this->data['templateId'] = $headers['id']; if (!empty($headers['language'])) { $this->data['language'] = $headers['language']; } $variables = $email->viewVars(); $variables['subject'] = $headers['Subject']; $recipients = array_merge($email->to(), $email->cc(), $email->bcc()); if (count($recipients) > 1) { $this->data['batch'] = array(); foreach ($recipients as $recipientEmail => $recipientName) { $this->data['batch'][] = array('variables' => $variables, 'templateId' => $headers['id'], 'recipientName' => $recipientName, 'recipientEmail' => $recipientEmail); } } else { $this->data['recipientName'] = reset($recipients); $this->data['recipientEmail'] = key($recipients); $this->data['variables'] = $variables; } $this->addAttachments($email); return $this->data; }
/** * 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; }
public function send($data) { $this->create(null); $this->set($data); $Invoice = ClassRegistry::init('LilInvoices.Invoice'); $Vat = ClassRegistry::init('LilInvoices.Vat'); $vats = $Vat->findList(); if ($this->validates() && ($invoices = $Invoice->find('all', array('conditions' => array('Invoice.id' => $data['InvoiceEmail']['invoices']), 'contain' => array('InvoicesItem', 'InvoicesCounter', 'Client' => 'PrimaryAddress', 'InvoicesAttachment', 'InvoicesTax' => 'Vat'))))) { // generate PDF App::uses('LilReport', 'Lil.Lib'); App::uses('Sanitize', 'Utility'); $report = new LilReport(); $report->helpers(array('Lil.Lil', 'Lil.LilDate', 'Lil.LilFloat', 'Html')); $report->template('', 'LilInvoices.lil_invoices_pdf'); $report->set(array('vats' => $vats)); $page = 0; foreach ($invoices as $i) { if ($page > 0) { $report->addPage(); } $report->set(array('data' => $i)); $report->render(null, array('template' => $i['InvoicesCounter']['layout'])); $page++; } $filename = 'invoices_' . strftime('%Y%m%d%H%M%S'); $report->output(TMP . $filename, 'F'); // init and send email App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail(); $email->template('LilInvoices.send_invoice'); $email->from(Configure::read('Lil.from.email'), Configure::read('Lil.from.name')); $email->returnPath(Configure::read('Lil.from.email')); $email->subject($data['InvoiceEmail']['subject']); $email->to($data['InvoiceEmail']['to']); if (!empty($data['InvoiceEmail']['cc']) && $data['InvoiceEmail']['cc'] != $data['InvoiceEmail']['to']) { $email->cc($data['InvoiceEmail']['cc']); } Cache::write('LilInvoices.emailCacheSubject', $data['InvoiceEmail']['subject'], 'Lil'); Cache::write('LilInvoices.emailCacheBody', $data['InvoiceEmail']['body'], 'Lil'); Cache::write('LilInvoices.emailCacheCC', $data['InvoiceEmail']['cc'], 'Lil'); if (isset($data['InvoiceEmail']['cc_me'])) { Cache::write('LilInvoices.emailCacheCCMe', $data['InvoiceEmail']['cc_me'], 'Lil'); } Cache::write('LilInvoices.emailCacheTo', $data['InvoiceEmail']['to'], 'Lil'); $email->viewVars(array('body' => $data['InvoiceEmail']['body'], 'invoices' => $invoices)); $ats = array($filename . '.pdf' => array('file' => TMP . $filename . '.pdf', 'mimetype' => 'application/pdf')); App::uses('Sanitize', 'Utility'); foreach ($invoices as $i) { foreach ($i['InvoicesAttachment'] as $atch) { $atch_name = 'at_' . $i['Invoice']['no'] . '_' . $atch['original']; $atch_file = APP . 'uploads' . DS . 'Invoice' . DS . $atch['filename']; if (file_exists($atch_file)) { $ats[Sanitize::paranoid($atch_name, array('-', '_', '.'))] = array('file' => $atch_file, 'mimetype' => $atch['mimetype']); } } } $email->attachments($ats); $result = $email->send(); unlink(TMP . $filename . '.pdf'); return $result; } return false; }
public function sendEmail($receipient, $cc, $subject, $msg, $replyto) { $email = new CakeEmail('smtp'); $email->sendAs = 'text'; //FIXME(Balaji Kutty, 2012-05-25) //Unable to get the template working with email. Fix it. //$email->template = 'passwd_reset'; //$email->set('password', $str); $email->delivery = 'smtp'; if ($replyto != null) { $email->replyTo($replyto); } $email->subject($subject); $email->to($receipient); if ($cc != null) { $email->cc($cc); } $email->helpers(array("Html")); $email->template("default"); $email->emailFormat("html"); if ($email->send($msg)) { return true; } }
/** * Wrapper of CakeEmail object creation and submission. * @param $emailData * @param string $templateName * @param string $to * @param string $subjectBlockName * @param string $tag * @param string $locale * @param bool $debug * @param array $emailOptions * @return string * @throws Exception */ public static function sendEmail($emailData, $templateName = '', $to = '', $subjectBlockName = '', $tag = '', $locale = 'en-US', $debug = false, $emailOptions = array()) { if (empty($templateName) || empty($to) || empty($subjectBlockName)) { CakeLog::error('CRITICAL EXEPTION: In email library.'); CakeLog::error('Empty argument passed to email sender.'); throw new BadMethodCallException('Empty argument passed to email sender.', 1); return false; } // Since getting the data from Drupal happens in-line we need to check // for errors by seeing if we only get log_info back and nothing else. if (!empty($tag)) { $drupalData = array(); DruniqueAPIUtil::getData(['api_url' => 'email_text.json', 'params' => ['tag' => $tag], 'locale' => $locale], $drupalData); if (sizeof($drupalData) <= 1) { CakeLog::error('CRITICAL EXEPTION: In email library.'); CakeLog::error('Unable to get view variables from CMS.'); throw new Exception('Unable to get view variables from CMS.', 1); return false; } $emailData['email_text'] = $drupalData; } $email = new CakeEmail('default'); $subject = DruniqueAPIUtil::content($subjectBlockName, $emailData['email_text']); $subject = preg_replace('/[\\pZ\\pC]/u', ' ', $subject); if ($debug) { $email->transport('Debug'); } // Make sure format is set correctly based on existence of templates. $format = 'both'; $htmlTemplateExists = is_readable(APP . "View/Emails/html/{$templateName}.ctp"); $textTemplateExists = is_readable(APP . "View/Emails/text/{$templateName}.ctp"); if (!$htmlTemplateExists && !$textTemplateExists) { CakeLog::error('CRITICAL ERROR: In email library.'); CakeLog::error("Unable to find email template named {$templateName}.ctp"); return false; } elseif (!$htmlTemplateExists && $textTemplateExists) { $format = 'text'; } elseif ($htmlTemplateExists && !$textTemplateExists) { $format = 'html'; } $email->template($templateName, 'default')->emailFormat($format)->to($to)->subject(html_entity_decode($subject, ENT_QUOTES))->viewVars($emailData); if (isset($emailOptions['bcc'])) { $email->bcc($emailOptions['bcc']); } if (isset($emailOptions['cc'])) { $email->cc($emailOptions['cc']); } try { $response = $email->send(); if ($debug) { return $response; } if ($response) { $result = 'Email was sent successfully'; } else { $result = 'Email failed to send without exceptions'; CakeLog::error('CRITICAL ERROR: Email library failed to send an email without exception.'); Cakelog::error(print_r($email, true)); } } catch (Exception $e) { $result = 'Email failed with exception: ' . print_r($e->getMessage(), true); CakeLog::error('CRITICAL ERROR: In email library.'); CakeLog::error($e->getMessage()); } return $result; }
private function __sendChangedEmail($data = null) { $email = new CakeEmail('default'); $email->viewVars(array('data' => $data)); $email->template('notice_change_advisor_email')->emailFormat('html')->to($data['email'])->subject('【ご意見番事務局】メールアドレスが変更されました'); $this->autoRender = false; $cc = Configure::read('MailSetting.CC'); if (!empty($cc)) { $email->cc($cc); } $email->send(); }
public function enviar($id = null) { $this->layout = "ajax"; $this->autoRender = false; $this->Reuniao->id = $id; $this->Reuniao->recursive = 2; if (!$this->Reuniao->exists()) { throw new NotFoundException(__(Util::REGISTRO_NAO_ENCONTRADO)); } if ($this->request->is('post')) { $reuniao = $this->Reuniao->read(null, $id); $emails = array(); $this->loadModel('Usuario'); foreach ($reuniao['ReuniaoParticipante'] as $key => $value) { $usuario = $this->Usuario->find('first', array('conditions' => array('Usuario.id' => $value['usuario_id']))); $emails[] = $usuario['Pessoa']['email']; $emailsTitulo[] = $usuario['Pessoa']['titulo']; } foreach ($reuniao['ReuniaoConhecedor'] as $key => $value) { $usuario = $this->Usuario->find('first', array('conditions' => array('Usuario.id' => $value['usuario_id']))); $emails[] = $usuario['Pessoa']['email']; $emailsTitulo[] = $usuario['Pessoa']['titulo']; } if (count($reuniao['ReuniaoEmailExterno']) > 0) { foreach ($reuniao['ReuniaoEmailExterno'] as $key => $value) { if ($value['email'] != "") { $emails[] = $value['email']; } } } } $usuarioLogado = $this->Auth->user(); $Email = new CakeEmail('smtp'); $Email->from(array('*****@*****.**' => 'SIGESPU')); $Email->to($emails); $Email->cc($usuarioLogado['Pessoa']['email']); $Email->emailFormat('html'); $Email->viewVars(array('assunto' => $reuniao['Reuniao']['titulo'], 'pauta' => $reuniao['Reuniao']['pauta'], 'observacao' => $reuniao['Reuniao']['observacao'], 'participantes' => implode(",", $emailsTitulo), 'local' => $reuniao['Reuniao']['local'], 'data' => $reuniao['Reuniao']['data'], 'ata' => $reuniao['Reuniao']['ata'], 'horario' => $reuniao['Reuniao']['hora_inicio'])); $Email->template('reuniao'); $Email->subject($reuniao['Reuniao']['titulo']); $Email->send(); echo "Emails enviados com sucesso"; }
/** * Utility method to send basic emails based on a paypal IPN transaction. * This method is very basic, if you need something more complicated I suggest * creating your own method in the afterPaypalNotification function you build * in the app_controller.php * * Example Usage: (InstantPaymentNotification = IPN) * IPN->id = '4aeca923-4f4c-49ec-a3af-73d3405bef47'; * IPN->email('Thank you for your transaction!'); * * IPN->email(array( * 'id' => '4aeca923-4f4c-49ec-a3af-73d3405bef47', * 'subject' => 'Donation Complete!', * 'message' => 'Thank you for your donation!', * 'sendAs' => 'text' * )); * * Hint: use this in your afterPaypalNotification callback in your app_controller.php * function afterPaypalNotification($txnId){ * ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array( * 'id' => $txnId, * 'subject' => 'Thanks!', * 'message' => 'Thank you for the transaction!' * )); * } * * Options: * id: id of instant payment notification to base email off of * subject: subject of email (default: Thank you for your paypal transaction) * sendAs: html | text (default: html) * to: email address to send email to (default: ipn payer_email) * from: from email address (default: ipn business) * cc: array of email addresses to carbon copy to (default: array()) * bcc: array of email addresses to blind carbon copy to (default: array()) * layout: layout of email to send (default: default) * template: template of email to send (default: null) * log: boolean true | false if you'd like to log the email being sent. (default: true) * message: actual body of message to be sent (default: null) * * @param array $options of the ipn to send * */ public function email($options = array()) { if (!is_array($options)) { $message = $options; $options = array(); $options['message'] = $message; } if (isset($options['id'])) { $this->id = $options['id']; } $this->read(); $defaults = array('subject' => 'Thank you for your paypal transaction', 'sendAs' => 'html', 'to' => $this->data['InstantPaymentNotification']['payer_email'], 'from' => $this->data['InstantPaymentNotification']['business'], 'cc' => array(), 'bcc' => array(), 'layout' => 'default', 'template' => null, 'log' => true, 'message' => null, 'config' => 'default'); $options = array_merge($defaults, $options); //debug($options); if ($options['log']) { $this->log("Emailing: {$options['to']} through the PayPal IPN Plugin. ", 'email'); } $fullname = sprintf('%s %s', $this->data['InstantPaymentNotification']['first_name'], $this->data['InstantPaymentNotification']['last_name']); App::uses('CakeEmail', 'Network/Email'); $Email = new CakeEmail($options['config']); $Email->to($options['to'], $fullname)->from($options['from'])->subject($options['subject'])->emailFormat($options['sendAs'])->template($options['template'], $options['layout']); if (!empty($options['bcc'])) { $Email->bcc($options['bcc']); } if (!empty($options['cc'])) { $Email->cc($options['cc']); } //Send the message. if ($options['message']) { $Email->send($options['message']); } else { $Email->send(); } }
/** * testRcpt method * * @return void */ public function testRcpt() { $email = new CakeEmail(); $email->from('*****@*****.**', 'CakePHP Test'); $email->to('*****@*****.**', 'CakePHP'); $email->bcc('*****@*****.**'); $email->cc(array('*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso')); $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<*****@*****.**>\r\n"); $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n")); $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<*****@*****.**>\r\n"); $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n")); $this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<*****@*****.**>\r\n"); $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false)); $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n")); $this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<*****@*****.**>\r\n"); $this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false)); $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n")); $this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<*****@*****.**>\r\n"); $this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false)); $this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n")); $this->SmtpTransport->setCakeEmail($email); $this->SmtpTransport->sendRcpt(); }
protected function _getEmailByNewStyleCharset($charset, $headerCharset) { $email = new CakeEmail(array('transport' => 'Debug')); if (! empty($charset)) { $email->charset($charset); } if (! empty($headerCharset)) { $email->headerCharset($headerCharset); } $email->from('*****@*****.**', 'どこかの誰か'); $email->to('*****@*****.**', 'どこかのどなたか'); $email->cc('*****@*****.**', 'ミク'); $email->subject('テストメール'); $email->send('テストメールの本文'); return $email; }
public function sendFeedback() { if ($this->request->is('post') || $this->request->is('put')) { $data = $this->request->data['User']; $emailProfile = Configure::read('emailProfile'); $Email = new CakeEmail($emailProfile); $Email->from(array($data['email'] => $data['email'])); $Email->to("*****@*****.**"); $Email->cc(array('*****@*****.**', '*****@*****.**')); $Email->subject('[MARKYT] ' . $data['subject']); $data["body"] = $data["body"] . "<p>==============================</p><h2>Please don't reply</h2>"; App::import('Vendor', 'HTMLPurifier', array('file' => 'htmlpurifier' . DS . 'library' . DS . 'HTMLPurifier.auto.php')); $config = HTMLPurifier_Config::createDefault(); $dirty_html = $data["body"]; $purifier = new HTMLPurifier($config); $data["body"] = $purifier->purify($dirty_html); $Email->replyTo($data['email']); // $this->Email->from = 'Cool Web App <*****@*****.**>'; $Email->emailFormat('html'); // $Email->template('recoverMarky'); // $Email->viewVars(array('user' => $userFind['User']['username'], // 'password' => $newPassword)); $send = $Email->send($data["body"]); if ($send) { return $this->correctResponseJson(json_encode(array('success' => true))); } else { CakeLog::write('MailLog', 'Error send password to: ' . $data['email']); return $this->correctResponseJson(json_encode(array('success' => false))); } } }