public static function send($headers, $to, $from, $subject, $body, $priority = 0, $attachments = null) { global $wgEnotifMaxRecips, $wgSMTP; wfProfileIn(__METHOD__); require_once 'Mail2.php'; require_once 'Mail2/mime.php'; $logContext = array_merge($headers, ['issue' => 'SOC-910', 'method' => __METHOD__, 'to' => $to, 'subject' => $subject]); WikiaLogger::instance()->info('Queuing email for SendGrid', $logContext); wfSuppressWarnings(); $headers['Subject'] = UserMailer::quotedPrintable($subject); // Add a header for the server-name (helps us route where SendGrid will send bounces). if (!empty($_SERVER) && isset($_SERVER['SERVER_NAME'])) { $headers["X-ServerName"] = $_SERVER['SERVER_NAME']; } try { $mail_object =& Mail2::factory(WikiaSendgridMailer::$factory, $wgSMTP); } catch (Exception $e) { $logContext['errorMessage'] = $e->getMessage(); WikiaLogger::instance()->info('Failed to create mail object', $logContext); wfDebug("PEAR::Mail factory failed: " . $e->getMessage() . "\n"); wfRestoreWarnings(); wfProfileOut(__METHOD__); return $e->getMessage(); } $email_body_txt = $email_body_html = ""; if (is_array($body)) { if (isset($body['text'])) { $email_body_txt = $body['text']; } if (isset($body['html'])) { $email_body_html = $body['html']; } } else { $email_body_txt = $body; } $mime = new Mail_mime(); $mime->setTXTBody($email_body_txt); $params = array('head_charset' => 'UTF-8', 'html_charset' => 'UTF-8', 'text_charset' => 'UTF-8', 'text_encoding' => 'quoted-printable', 'html_encoding' => 'quoted-printable'); # send email with attachements if (!empty($attachments)) { if (!is_array($attachments)) { $attachments = array($attachments); } foreach ($attachments as $file) { if (!is_array($file)) { $magic = MimeMagic::singleton(); $mimeType = $magic->guessMimeType($file); $ext_file = end(explode('.', $file)); $file = array('file' => $file, 'ext' => $ext_file, 'mime' => $mimeType); } $filename = $file['file']; $ext_filename = $file['ext']; if (!file_exists($filename)) { continue; } $name = $filename; #basename( $filename ); if ($ext_filename) { $name = $filename . "." . $ext_filename; } $mime->addAttachment($filename, $file['mime'], $name); } } # Old version (1.16 MW with Wikia changes) of sendHTML method if ($email_body_html) { $mime->setHTMLBody($email_body_html); //do not ever try to call these lines in reverse order } $body = $mime->get($params); $headers = $mime->headers($headers); wfDebug("Sending mail via WikiaSendgridMailer::send\n"); $chunks = array_chunk((array) $to, $wgEnotifMaxRecips); foreach ($chunks as $chunk) { $headers['To'] = $chunk; $status = self::sendWithPear($mail_object, $chunk, $headers, $body); if (!$status->isOK()) { $logContext['errorMessage'] = $status->getMessage(); WikiaLogger::instance()->info('Failed to create mail object', $logContext); wfRestoreWarnings(); wfProfileOut(__METHOD__); return $status->getMessage(); } } wfProfileOut(__METHOD__); # return false to return Status::newGood() in UserMailer::send method return false; }
/** * Send the mail. * This method is used to send a generated email. When calling this method, * the template itself is compiled. Afterwards, the existing headers are merged * with the additional header submited to this method. * * @since * @access public * @param array $headers Additional headers to use when sending an email. Note, that * none of these headers will overwrite existing headers, set in * the template. If a header already exists in the template * @return void */ function send($headers = array()) { // Compile the template $data = $this->_compile(); if (PEAR::isError($data)) { return $data; } // Merge additional header information to the generated data $data = $this->_mergeHeaders($data, $headers); if (PEAR::isError($data)) { return $data; } // Check sanity of the email headers $data = $this->_sanitize($data); if (PEAR::isError($data)) { return $data; } // Restructure data for use with PEAR::Mail (To-header and body are submitted directly) foreach ($data as $field => $content) { switch (strtolower($field)) { case 'to': $to = $content; unset($data[$field]); break; case 'body': $body = $content; unset($data[$field]); break; default: if (is_array($content)) { $data[$field] = implode(', ', $content); } break; } } // Attempt to send mail: $mail = Mail2::factory('mail', array('-f bounces-ignored@php.net')); $mail->send($to, $data, $body); return true; }
function __construct() { parent::__construct(); $this->_mailer = Mail2::factory('mail', '-f ' . PEAR_BOUNCE_EMAIL); $this->_headers['From'] = "\"PEAR System Administrators\" <*****@*****.**>"; }
/** * Provides an interface for generating Mail:: objects of various * types see Mail::factory(). * * @return void */ protected function factorySendMail() { $options = $this->mail_options; unset($options['driver']); $this->send_mail = Mail2::factory($this->mail_options['driver'], $options); }