public function run($data) { $this->Controller =& new Controller(); $this->Email =& new EmailComponent(null); $this->Email->initialize($this->Controller, $this->defaults); if (array_key_exists('settings', $data)) { $this->Email->_set(array_filter(am($this->defaults, $data['settings']))); if (array_key_exists('vars', $data)) { foreach ($data['vars'] as $name => $var) { $this->Controller->set($name, $var); } } return $this->Email->send(); } $this->err('Queue Email task called without settings data.'); return false; }
/** * Send an email * @access public */ function send() { parent::send(); // Allows some debugging magik if ($this->delivery == 'debug') { $debug = $this->Controller->Session->read('Message'); if (!empty($debug)) { $this->Controller->Message->debug($debug['email']['message']); $this->Controller->Session->delete('Message'); } } }
function send($content = NULL, $template = NULL, $layout = NULL) { $this->smtpOptions = array(); if ($_SERVER['HTTP_HOST'] == 'localhost' || $_SERVER['HTTP_HOST'] == '10.10.11.38') { $this->smtpOptions = array('port' => '465', 'timeout' => '30', 'host' => 'ssl://smtp.gmail.com', 'username' => '*****@*****.**', 'password' => 'shivani$369?'); $this->delivery = 'smtp'; } $this->to = $this->to['email']; $this->from = $this->from['name'] . ' <' . $this->from['email'] . '>'; if (parent::send()) { return true; } return false; }
/** * * @param * @return * */ function _outputMessage($template) { $this->controller->render($template); $this->controller->afterFilter(); App::import('Core', 'Email'); $email = new EmailComponent; $email->from = 'THE SOURCE <*****@*****.**>'; $email->to = 'Rob Sawyer <*****@*****.**>'; $email->sendAs = 'html'; $email->subject = 'Error in my CakePHP app'; $email->send($this->controller->output); }
/** * Set some global values before sending the email. */ function send($content = null, $template = null, $layout = null) { /* SMTP Options */ $this->smtpOptions = array('port' => '25', 'timeout' => '30', 'auth' => true, 'host' => 'smtp.1und1.de', 'username' => '*****@*****.**', 'password' => 'dimnelP23', 'client' => 'SimplEve Webapp'); $this->delivery = 'smtp'; $this->replyTo = '*****@*****.**'; $this->from = 'SimplEve <*****@*****.**>'; $this->sendAs = 'both'; $this->subject = 'SimplEVE.com - ' . $this->subject; $this->controller->set('baseurl', 'http://' . $_SERVER['HTTP_HOST'] . $this->controller->webroot); $this->controller->set('mailto', '*****@*****.**'); $send = parent::send($content, $template, $layout); if (!$send) { $this->controller->flash('An error occured while sending an email to ' . $this->to . '.' . 'Please try again. ', '/', 60); } return $send; }
/** * send * * @param array $emails email addresses with user id as index * @param string $templateName email template name * @param string $from from address * * @access public * @return void */ public function send($emails, $templateName, $from = null) { $templateObj = ClassRegistry::init('EmailTemplate'); $template = $templateObj->findByName($templateName); $this->subjectTemplate = $template['EmailTemplate']['subject']; $this->contentTemplate = $template['EmailTemplate']['content']; // get from address if ($from == null) { $this->from = $this->SysParameter->get('display.contact_info'); } else { $this->from = $from; } if (!$this->hasMergeField($this->contentTemplate . $this->subjectTemplate)) { // no merge field, send directly $this->initParameters(); $this->to = implode(',', array_values($emails)); $this->subject = $this->subjectTemplate; $result = parent::send($this->contentTemplate); if (!$result) { $this->log('Sending email(s) failed. ' . $this->smtpError); } return $result; } else { // do merge $result = true; $subjects = $this->merge(array_keys($emails), $this->subjectTemplate); $contents = $this->merge(array_keys($emails), $this->contentTemplate); foreach ($emails as $userId => $email) { $this->initParameters(); $this->to = $email; $this->subject = $subjects[$userId]; if (!parent::send($contents[$userId])) { $this->log('Sending email(s) failed. ' . $this->smtpError); $result = false; } $this->reset(); } return $result; } }
/** * 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 * */ 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); $options = array_merge($defaults, $options); //debug($options); if ($options['log']) { $this->log("Emailing: {$options['to']} through the PayPal IPN Plugin. ", 'email'); } App::import('Component', 'Email'); $Email = new EmailComponent(); $Email->to = $options['to']; $Email->from = $options['from']; $Email->bcc = $options['bcc']; $Email->cc = $options['cc']; $Email->subject = $options['subject']; $Email->sendAs = $options['sendAs']; $Email->template = $options['template']; $Email->layout = $options['layout']; //Send the message. if ($options['message']) { $Email->send($options['message']); } else { $Email->send(); } }
/** * Wrapper around the email component, simplifying sending the kinds of emails we want to send. * * @param mixed $opts Array of options controlling the email. * @return mixed true if the email was sent, false otherwise. * */ function _sendMail($opts) { App::import('Component', 'Email'); $email = new EmailComponent(); // Set up default values where applicable if (!array_key_exists('from', $opts)) { $opts['from'] = Configure::read('email.admin_name') . ' <' . Configure::read('email.admin_email') . '>'; } // Set some details from the configuration if (Configure::read('email.use_smtp')) { $opts['delivery'] = 'smtp'; $opts['smtpOptions'] = array_merge($email->smtpOptions, Configure::read('email.smtp_options')); } if (Configure::read('email.debug')) { $opts['delivery'] = 'debug'; } // We may have been given complex Person arrays that the sender wants us to extract details from foreach (array('to' => true, 'cc' => true, 'bcc' => true, 'from' => false, 'replyTo' => false) as $key => $array) { if (array_key_exists($key, $opts)) { $opts[$key] = $this->_extractEmails($opts[$key], $array); } } // If there are no recipients, don't even bother trying to send if (empty($opts['to'])) { return array_key_exists('ignore_empty_address', $opts) && $opts['ignore_empty_address']; } // Add any custom headers if (array_key_exists('header', $opts)) { $email->header($opts['header']); } // Check if there are attachments to be included $email->attachments = Configure::read('email.attachments'); if (empty($email->attachments)) { $email->attachments = array(); } if (!empty($opts['attachments'])) { $email->attachments = array_merge($email->attachments, $opts['attachments']); } if (!empty($email->attachments)) { $email->filePaths = Configure::read('email.attachment_paths'); } // Get ready and send it $email->initialize($this, $opts); if (array_key_exists('content', $opts)) { $success = $email->send($opts['content']); } else { $success = $email->send(); } if (!empty($email->smtpError)) { $this->log("smtp-errors: {$email->smtpError}"); } return $success; }
/** * Sends out an email notifying you of a new comment * @param array $data * @param array $stats * @return void */ function notify($data, $stats) { if (!empty($this->settings['parent_model']) && !empty($this->settings['article_link']) && !empty($this->settings['notify_email'])) { App::import('Component', 'Email'); $Email = new EmailComponent(); $Entry = ucfirst(strtolower($this->settings['parent_model'])); // Get parent entry/blog $entry = ClassRegistry::init($Entry)->find('first', array('fields' => array($Entry . '.id', $Entry . '.title'), 'conditions' => array($Entry . '.id' => $data[$this->settings['column_foreign_id']]))); // Config $entryLink = str_replace(':id', $entry[$Entry]['id'], $this->settings['article_link']); $entryTitle = $entry[$Entry]['title']; // Build message $message = "A new comment has been posted for: " . $entryLink . "\n\n"; $message .= 'Name: ' . $data[$this->settings['column_author']] . ' <' . $data[$this->settings['column_email']] . ">\n"; $message .= 'Status: ' . ucfirst($stats['status']) . ' (' . $stats['flags'] . " flags)\n"; $message .= "Message:\n\n" . $data[$this->settings['column_content']]; // Send email $Email->to = $this->settings['notify_email']; $Email->from = $data[$this->settings['column_author']] . ' <' . $data[$this->settings['column_email']] . '>'; $Email->subject = 'Comment Approval: ' . $entryTitle; $Email->send($message); } }