/** * Inner mailer initialization from set variables * * @return void */ protected function initMailFromSet() { $this->mail->SetLanguage($this->get('langLocale'), $this->get('langPath')); $this->mail->CharSet = $this->get('charset'); $this->mail->From = $this->get('from'); $this->mail->FromName = $this->get('from'); $this->mail->Sender = $this->get('from'); $this->mail->ClearAllRecipients(); $this->mail->ClearAttachments(); $this->mail->ClearCustomHeaders(); $emails = explode(static::MAIL_SEPARATOR, $this->get('to')); foreach ($emails as $email) { $this->mail->AddAddress($email); } $this->mail->Subject = $this->get('subject'); $this->mail->AltBody = $this->createAltBody($this->get('body')); $this->mail->Body = $this->get('body'); // add custom headers foreach ($this->get('customHeaders') as $header) { $this->mail->AddCustomHeader($header); } if (is_array($this->get('images'))) { foreach ($this->get('images') as $image) { // Append to $attachment array $this->mail->AddEmbeddedImage($image['path'], $image['name'] . '@mail.lc', $image['name'], 'base64', $image['mime']); } } }
/** * Miscellaneous calls to improve test coverage and some small tests */ function test_Miscellaneous() { $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed'); $this->Mail->AddCustomHeader('SomeHeader: Some Value'); $this->Mail->ClearCustomHeaders(); $this->Mail->ClearAttachments(); $this->Mail->IsHTML(false); $this->Mail->IsSMTP(); $this->Mail->IsMail(); $this->Mail->IsSendMail(); $this->Mail->IsQmail(); $this->Mail->SetLanguage('fr'); $this->Mail->Sender = ''; $this->Mail->CreateHeader(); $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded'); $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed'); //Test pathinfo $a = '/mnt/files/飛兒樂 團光茫.mp3'; $q = PHPMailer::mb_pathinfo($a); $this->assertEquals($q['dirname'], '/mnt/files', 'UNIX dirname not matched'); $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'UNIX basename not matched'); $this->assertEquals($q['extension'], 'mp3', 'UNIX extension not matched'); $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'UNIX filename not matched'); $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_DIRNAME), '/mnt/files', 'Dirname path element not matched'); $this->assertEquals(PHPMailer::mb_pathinfo($a, 'filename'), '飛兒樂 團光茫', 'Filename path element not matched'); $a = 'c:\\mnt\\files\\飛兒樂 團光茫.mp3'; $q = PHPMailer::mb_pathinfo($a); $this->assertEquals($q['dirname'], 'c:\\mnt\\files', 'Windows dirname not matched'); $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'Windows basename not matched'); $this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched'); $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched'); }
/** * Miscellaneous calls to improve test coverage and some small tests */ function test_Miscellaneous() { $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed'); $this->Mail->AddCustomHeader('SomeHeader: Some Value'); $this->Mail->ClearCustomHeaders(); $this->Mail->ClearAttachments(); $this->Mail->IsHTML(false); $this->Mail->IsSMTP(); $this->Mail->IsMail(); $this->Mail->IsSendMail(); $this->Mail->IsQmail(); $this->Mail->SetLanguage('fr'); $this->Mail->Sender = ''; $this->Mail->CreateHeader(); $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded'); $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed'); }
static function old_send_email($to, $subject, $html, $text, $istest = false, $sid, $list_id, $report_id) { global $phpmailer, $wpdb; // (Re)create it, if it's gone missing if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(); } /* * Make sure the mailer thingy is clean before we start, should not * be necessary, but who knows what others are doing to our mailer */ $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); //return $email; // $charset = SendPress_Option::get('email-charset', 'UTF-8'); $encoding = SendPress_Option::get('email-encoding', '8bit'); $phpmailer->CharSet = $charset; $phpmailer->Encoding = $encoding; if ($charset != 'UTF-8') { $sender = new SendPress_Sender(); $html = $sender->change($html, 'UTF-8', $charset); $text = $sender->change($text, 'UTF-8', $charset); $subject = $sender->change($subject, 'UTF-8', $charset); } $subject = str_replace(array('’', '“', '�', '–'), array("'", '"', '"', '-'), $subject); $html = str_replace(chr(194), chr(32), $html); $text = str_replace(chr(194), chr(32), $text); $phpmailer->AddAddress(trim($to)); $phpmailer->AltBody = $text; $phpmailer->Subject = $subject; $phpmailer->MsgHTML($html); $content_type = 'text/html'; $phpmailer->ContentType = $content_type; // Set whether it's plaintext, depending on $content_type //if ( 'text/html' == $content_type ) $phpmailer->IsHTML(true); /** * We'll let php init mess with the message body and headers. But then * we stomp all over it. Sorry, my plug-inis more important than yours :) */ do_action_ref_array('phpmailer_init', array(&$phpmailer)); $from_email = SendPress_Option::get('fromemail'); $phpmailer->From = $from_email; $phpmailer->FromName = SendPress_Option::get('fromname'); $phpmailer->Sender = SendPress_Option::get('fromemail'); $sending_method = SendPress_Option::get('sendmethod'); $phpmailer = apply_filters('sendpress_sending_method_' . $sending_method, $phpmailer); $hdr = new SendPress_SendGrid_SMTP_API(); $hdr->addFilterSetting('dkim', 'domain', SendPress_Manager::get_domain_from_email($from_email)); $phpmailer->AddCustomHeader(sprintf('X-SMTPAPI: %s', $hdr->asJSON())); $phpmailer->AddCustomHeader('X-SP-METHOD: old'); // Set SMTPDebug to 2 will collect dialogue between us and the mail server if ($istest == true) { $phpmailer->SMTPDebug = 2; // Start output buffering to grab smtp output ob_start(); } // Send! $result = true; // start with true, meaning no error $result = @$phpmailer->Send(); //$phpmailer->SMTPClose(); if ($istest == true) { // Grab the smtp debugging output $smtp_debug = ob_get_clean(); SendPress_Option::set('phpmailer_error', $phpmailer->ErrorInfo); SendPress_Option::set('last_test_debug', $smtp_debug); } if ($result != true && $istest == true) { $hostmsg = 'host: ' . $phpmailer->Host . ' port: ' . $phpmailer->Port . ' secure: ' . $phpmailer->SMTPSecure . ' auth: ' . $phpmailer->SMTPAuth . ' user: '******''; $msg .= __('The result was: ', 'sendpress') . $result . "\n"; $msg .= __('The mailer error info: ', 'sendpress') . $phpmailer->ErrorInfo . "\n"; $msg .= $hostmsg; $msg .= __("The SMTP debugging output is shown below:\n", "sendpress"); $msg .= $smtp_debug . "\n"; } return $result; }
function mail($to, $subject, $message, $headers = null) { $this->logger->debug('mail> To: ' . $to); $this->logger->debug('mail> Subject: ' . $subject); if (empty($subject)) { $this->logger->debug('mail> Subject empty, skipped'); return true; } // Message carrige returns and line feeds clean up if (!is_array($message)) { $message = str_replace("\r\n", "\n", $message); $message = str_replace("\r", "\n", $message); $message = str_replace("\n", "\r\n", $message); } else { if (!empty($message['text'])) { $message['text'] = str_replace("\r\n", "\n", $message['text']); $message['text'] = str_replace("\r", "\n", $message['text']); $message['text'] = str_replace("\n", "\r\n", $message['text']); } if (!empty($message['html'])) { $message['html'] = str_replace("\r\n", "\n", $message['html']); $message['html'] = str_replace("\r", "\n", $message['html']); $message['html'] = str_replace("\n", "\r\n", $message['html']); } } if ($this->mail_method != null) { return call_user_func($this->mail_method, $to, $subject, $message, $headers); } if ($this->mailer == null) { $this->mailer_init(); } // Simple message is asumed to be html if (!is_array($message)) { $this->mailer->IsHTML(true); $this->mailer->Body = $message; } else { // Only html is present? if (empty($message['text'])) { $this->mailer->IsHTML(true); $this->mailer->Body = $message['html']; } else { if (empty($message['html'])) { $this->mailer->IsHTML(false); $this->mailer->Body = $message['text']; } else { $this->mailer->IsHTML(true); $this->mailer->Body = $message['html']; $this->mailer->AltBody = $message['text']; } } } $this->mailer->Subject = $subject; $this->mailer->ClearCustomHeaders(); if (!empty($headers)) { foreach ($headers as $key => $value) { $this->mailer->AddCustomHeader($key . ': ' . $value); } } $this->mailer->ClearAddresses(); $this->mailer->AddAddress($to); $this->mailer->Send(); if ($this->mailer->IsError()) { $this->logger->error('mail> ' . $this->mailer->ErrorInfo); // If the error is due to SMTP connection, the mailer cannot be reused since it does not clean up the connection // on error. $this->mailer = null; return false; } return true; }
/** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received the * email successfully. It just only means that the method used was able to * process the request without any errors. * * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from * creating a from address like 'Name <*****@*****.**>' when both are set. If * just 'wp_mail_from' is set, then just the email address will be used with no * name. * * The default content type is 'text/plain' which does not allow using HTML. * However, you can set the content type of the email by using the * 'wp_mail_content_type' filter. * * The default charset is based on the charset used on the blog. The charset can * be set using the 'wp_mail_charset' filter. * * @since 1.2.1 * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters. * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address. * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name. * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type. * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to * phpmailer object. * @uses PHPMailer * @ * * @param string $to Email address to send message * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. * @return bool Whether the email contents were sent successfully. */ function wp_mail($to, $subject, $message, $headers = '') { // Compact the input, apply the filters, and extract them back out extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers'))); global $phpmailer; // (Re)create it, if it's gone missing if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(); } // Headers if (empty($headers)) { $headers = array(); } elseif (!is_array($headers)) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = (array) explode("\n", $headers); $headers = array(); // If it's actually got contents if (!empty($tempheaders)) { // Iterate through the raw headers foreach ($tempheaders as $header) { if (strpos($header, ':') === false) { continue; } // Explode them out list($name, $content) = explode(':', trim($header), 2); // Cleanup crew $name = trim($name); $content = trim($content); // Mainly for legacy -- process a From: header if it's there if ('from' == strtolower($name)) { if (strpos($content, '<') !== false) { // So... making my life hard again? $from_name = substr($content, 0, strpos($content, '<') - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); $from_email = substr($content, strpos($content, '<') + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email); } else { $from_name = trim($content); } } elseif ('content-type' == strtolower($name)) { if (strpos($content, ';') !== false) { list($type, $charset) = explode(';', $content); $content_type = trim($type); $charset = trim(str_replace(array('charset=', '"'), '', $charset)); } else { $content_type = trim($content); } } elseif ('cc' == strtolower($name)) { $cc = explode(",", $content); } elseif ('bcc' == strtolower($name)) { $bcc = explode(",", $content); } else { // Add it to our grand headers array $headers[trim($name)] = trim($content); } } } } // Empty out the values that may be set $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if (!isset($from_name)) { $from_name = 'WordPress'; } // If we don't have an email from the input headers if (!isset($from_email)) { // Get the site domain and get rid of www. $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $from_email = 'wordpress@' . $sitename; } // Set the from name and email $phpmailer->From = apply_filters('wp_mail_from', $from_email); $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name); // Set destination address $phpmailer->AddAddress($to); // Set mail's subject and body $phpmailer->Subject = $subject; $phpmailer->Body = $message; // Add any CC and BCC recipients if (!empty($cc)) { foreach ($cc as $recipient) { $phpmailer->AddCc(trim($recipient)); } } if (!empty($bcc)) { foreach ($bcc as $recipient) { $phpmailer->AddBcc(trim($recipient)); } } // Set to use PHP's mail() $phpmailer->IsMail(); // Set Content-Type and charset // If we don't have a content-type from the input headers if (!isset($content_type)) { $content_type = 'text/plain'; } $content_type = apply_filters('wp_mail_content_type', $content_type); // Set whether it's plaintext or not, depending on $content_type if ($content_type == 'text/html') { $phpmailer->IsHTML(true); } else { $phpmailer->IsHTML(false); } // If we don't have a charset from the input headers if (!isset($charset)) { $charset = get_bloginfo('charset'); } // Set the content-type and charset $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); // Set custom headers if (!empty($headers)) { foreach ($headers as $name => $content) { $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } } do_action_ref_array('phpmailer_init', array(&$phpmailer)); // Send! $result = @$phpmailer->Send(); return $result; }
/** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received the * email successfully. It just only means that the method used was able to * process the request without any errors. * * Using the two 'bb_mail_from' and 'bb_mail_from_name' hooks allow from * creating a from address like 'Name <*****@*****.**>' when both are set. If * just 'bb_mail_from' is set, then just the email address will be used with no * name. * * The default content type is 'text/plain' which does not allow using HTML. * However, you can set the content type of the email by using the * 'bb_mail_content_type' filter. * * The default charset is based on the charset used on the blog. The charset can * be set using the 'bb_mail_charset' filter. * * @uses apply_filters() Calls 'bb_mail' hook on an array of all of the parameters. * @uses apply_filters() Calls 'bb_mail_from' hook to get the from email address. * @uses apply_filters() Calls 'bb_mail_from_name' hook to get the from address name. * @uses apply_filters() Calls 'bb_mail_content_type' hook to get the email content type. * @uses apply_filters() Calls 'bb_mail_charset' hook to get the email charset * @uses do_action_ref_array() Calls 'bb_phpmailer_init' hook on the reference to * phpmailer object. * @uses PHPMailer * * @param string $to Email address to send message * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Optional. Files to attach. * @return bool Whether the email contents were sent successfully. */ function bb_mail($to, $subject, $message, $headers = '', $attachments = array()) { // Compact the input, apply the filters, and extract them back out extract(apply_filters('bb_mail', compact('to', 'subject', 'message', 'headers', 'attachments'))); if (!is_array($attachments)) { $attachments = explode("\n", $attachments); } global $bb_phpmailer; // (Re)create it, if it's gone missing if (!is_object($bb_phpmailer) || !is_a($bb_phpmailer, 'PHPMailer')) { require_once BACKPRESS_PATH . 'class.mailer.php'; require_once BACKPRESS_PATH . 'class.mailer-smtp.php'; $bb_phpmailer = new PHPMailer(); } // Headers if (empty($headers)) { $headers = array(); } else { if (!is_array($headers)) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = (array) explode("\n", $headers); } else { $tempheaders = $headers; } $headers = array(); // If it's actually got contents if (!empty($tempheaders)) { // Iterate through the raw headers foreach ((array) $tempheaders as $header) { if (strpos($header, ':') === false) { if (false !== stripos($header, 'boundary=')) { $parts = preg_split('/boundary=/i', trim($header)); $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); } continue; } // Explode them out list($name, $content) = explode(':', trim($header), 2); // Cleanup crew $name = trim($name); $content = trim($content); // Mainly for legacy -- process a From: header if it's there if ('from' == strtolower($name)) { if (strpos($content, '<') !== false) { // So... making my life hard again? $from_name = substr($content, 0, strpos($content, '<') - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); $from_email = substr($content, strpos($content, '<') + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email); } else { $from_email = trim($content); } } elseif ('content-type' == strtolower($name)) { if (strpos($content, ';') !== false) { list($type, $charset) = explode(';', $content); $content_type = trim($type); if (false !== stripos($charset, 'charset=')) { $charset = trim(str_replace(array('charset=', '"'), '', $charset)); } elseif (false !== stripos($charset, 'boundary=')) { $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset)); $charset = ''; } } else { $content_type = trim($content); } } elseif ('cc' == strtolower($name)) { $cc = explode(",", $content); } elseif ('bcc' == strtolower($name)) { $bcc = explode(",", $content); } else { // Add it to our grand headers array $headers[trim($name)] = trim($content); } } } } // Empty out the values that may be set $bb_phpmailer->ClearAddresses(); $bb_phpmailer->ClearAllRecipients(); $bb_phpmailer->ClearAttachments(); $bb_phpmailer->ClearBCCs(); $bb_phpmailer->ClearCCs(); $bb_phpmailer->ClearCustomHeaders(); $bb_phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if (!isset($from_name)) { $from_name = bb_get_option('name'); } // If we don't have an email from the input headers if (!isset($from_email)) { $from_email = bb_get_option('from_email'); } // If there is still no email address if (!$from_email) { // Get the site domain and get rid of www. $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $from_email = 'bbpress@' . $sitename; } // Plugin authors can override the potentially troublesome default $bb_phpmailer->From = apply_filters('bb_mail_from', $from_email); $bb_phpmailer->FromName = apply_filters('bb_mail_from_name', $from_name); // Set destination address $bb_phpmailer->AddAddress($to); // Set mail's subject and body $bb_phpmailer->Subject = $subject; $bb_phpmailer->Body = $message; // Add any CC and BCC recipients if (!empty($cc)) { foreach ((array) $cc as $recipient) { $bb_phpmailer->AddCc(trim($recipient)); } } if (!empty($bcc)) { foreach ((array) $bcc as $recipient) { $bb_phpmailer->AddBcc(trim($recipient)); } } // Set to use PHP's mail() $bb_phpmailer->IsMail(); // Set Content-Type and charset // If we don't have a content-type from the input headers if (!isset($content_type)) { $content_type = 'text/plain'; } $content_type = apply_filters('bb_mail_content_type', $content_type); $bb_phpmailer->ContentType = $content_type; // Set whether it's plaintext or not, depending on $content_type if ($content_type == 'text/html') { $bb_phpmailer->IsHTML(true); } // If we don't have a charset from the input headers if (!isset($charset)) { $charset = bb_get_option('charset'); } // Set the content-type and charset $bb_phpmailer->CharSet = apply_filters('bb_mail_charset', $charset); // Set custom headers if (!empty($headers)) { foreach ((array) $headers as $name => $content) { $bb_phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } if (false !== stripos($content_type, 'multipart') && !empty($boundary)) { $bb_phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary)); } } if (!empty($attachments)) { foreach ($attachments as $attachment) { $bb_phpmailer->AddAttachment($attachment); } } do_action_ref_array('bb_phpmailer_init', array(&$bb_phpmailer)); // Send! $result = @$bb_phpmailer->Send(); return $result; }
/** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received the * email successfully. It just only means that the method used was able to * process the request without any errors. * * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from * creating a from address like 'Name <*****@*****.**>' when both are set. If * just 'wp_mail_from' is set, then just the email address will be used with no * name. * * The default content type is 'text/plain' which does not allow using HTML. * However, you can set the content type of the email by using the * 'wp_mail_content_type' filter. * * The default charset is based on the charset used on the blog. The charset can * be set using the 'wp_mail_charset' filter. * * @since 1.2.1 * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters. * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address. * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name. * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type. * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to * phpmailer object. * @uses PHPMailer * @ * * @param string|array $to Array or comma-separated list of email addresses to send message. * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Optional. Files to attach. * @return bool Whether the email contents were sent successfully. */ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { // Compact the input, apply the filters, and extract them back out extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'))); if (!is_array($attachments)) { $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); } global $phpmailer; // (Re)create it, if it's gone missing if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once BACKPRESS_PATH . '/class.mailer.php'; require_once BACKPRESS_PATH . '/class.mailer-smtp.php'; $phpmailer = new PHPMailer(); } // Headers if (empty($headers)) { $headers = array(); } else { if (!is_array($headers)) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers)); } else { $tempheaders = $headers; } $headers = array(); // If it's actually got contents if (!empty($tempheaders)) { // Iterate through the raw headers foreach ((array) $tempheaders as $header) { if (strpos($header, ':') === false) { if (false !== stripos($header, 'boundary=')) { $parts = preg_split('/boundary=/i', trim($header)); $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); } continue; } // Explode them out list($name, $content) = explode(':', trim($header), 2); // Cleanup crew $name = trim($name); $content = trim($content); switch (strtolower($name)) { // Mainly for legacy -- process a From: header if it's there case 'from': if (strpos($content, '<') !== false) { // So... making my life hard again? $from_name = substr($content, 0, strpos($content, '<') - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); $from_email = substr($content, strpos($content, '<') + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email); } else { $from_email = trim($content); } break; case 'content-type': if (strpos($content, ';') !== false) { list($type, $charset) = explode(';', $content); $content_type = trim($type); if (false !== stripos($charset, 'charset=')) { $charset = trim(str_replace(array('charset=', '"'), '', $charset)); } elseif (false !== stripos($charset, 'boundary=')) { $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset)); $charset = ''; } } else { $content_type = trim($content); } break; case 'cc': $cc = array_merge((array) $cc, explode(',', $content)); break; case 'bcc': $bcc = array_merge((array) $bcc, explode(',', $content)); break; case 'message-id': $message_id = trim($content); default: // Add it to our grand headers array $headers[trim($name)] = trim($content); break; } } } } // Empty out the values that may be set $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if (!isset($from_name)) { $from_name = 'WordPress'; } /* If we don't have an email from the input headers default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist but * there's no easy alternative. Defaulting to admin_email might appear to be another * option but some hosts may refuse to relay mail from an unknown domain. See * http://trac.wordpress.org/ticket/5007. */ if (!isset($from_email)) { // Get the site domain and get rid of www. $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $from_email = 'wordpress@' . $sitename; } // Plugin authors can override the potentially troublesome default $phpmailer->From = apply_filters('wp_mail_from', $from_email); $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name); // Set destination addresses if (!is_array($to)) { $to = explode(',', $to); } foreach ((array) $to as $recipient) { $phpmailer->AddAddress(trim($recipient)); } // Set mail's subject and body $phpmailer->Subject = $subject; $phpmailer->Body = $message; // Add any CC and BCC recipients if (!empty($cc)) { foreach ((array) $cc as $recipient) { $phpmailer->AddCc(trim($recipient)); } } if (!empty($bcc)) { foreach ((array) $bcc as $recipient) { $phpmailer->AddBcc(trim($recipient)); } } if (!empty($message_id)) { $phpmailer->MessageID = $message_id; } // Set to use PHP's mail() $phpmailer->IsMail(); // SupportPress: use STMP if configured if (defined('SMTP_HOST') && SMTP_HOST) { $phpmailer->IsSMTP(); $phpmailer->Host = SMTP_HOST; if (SMTP_PORT) { $phpmailer->Host .= ':' . SMTP_PORT; } global $email_domain; $phpmailer->Hostname = $email_domain; if (SMTP_USER) { $phpmailer->SMTPAuth = true; $phpmailer->Username = SMTP_USER; $phpmailer->Password = SMTP_PASSWORD; } } // Set Content-Type and charset // If we don't have a content-type from the input headers if (!isset($content_type)) { $content_type = 'text/plain'; } $content_type = apply_filters('wp_mail_content_type', $content_type); $phpmailer->ContentType = $content_type; // Set whether it's plaintext, depending on $content_type if ('text/html' == $content_type) { $phpmailer->IsHTML(true); } // If we don't have a charset from the input headers if (!isset($charset)) { $charset = 'utf-8'; } // Set the content-type and charset $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); // Set custom headers if (!empty($headers)) { foreach ((array) $headers as $name => $content) { $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } if (false !== stripos($content_type, 'multipart') && !empty($boundary)) { $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary)); } } if (!empty($attachments)) { foreach ($attachments as $attachment) { $phpmailer->AddAttachment($attachment); } } do_action_ref_array('phpmailer_init', array(&$phpmailer)); // Send! $result = @$phpmailer->Send(); return $result; }
/** * Send mail for a particular $comment * Inspired by code from the core for wp_mail function. * * @global PHPMailer $phpmailer * @param object $comment result of get_comment * @return boolean TRUE if all messages sent okay, FALSE if any individual send gives error. */ public function send($comment) { global $phpmailer; // get PHPMailer and SMTP classes, if not already available. if (!is_object($phpmailer) || !is_a($phpmailer, "PHPMailer")) { require_once ABSPATH . WPINC . "/class-phpmailer.php"; require_once ABSPATH . WPINC . "/class-smtp.php"; $phpmailer = new PHPMailer(TRUE); } $num_messages = $this->numMessages(); // send each message that has been loaded into this object: for ($mid = 0; $mid < $num_messages; $mid++) { $this->selectMessage($mid); $recipient_email = $comment->comment_author_email; $from_name = $this->getParsedFromName($comment); $from_email = $this->getParsedFromEmail($comment); $recipient_name = $comment->comment_author; $body_html = $this->getParsedHtmlMessage($comment); $body_plain = $this->getParsedPlainMessage($comment); // clear any previous PHPMailer settings $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // set from and subject $phpmailer->From = $from_email; $phpmailer->FromName = $from_name; $phpmailer->Subject = $this->getParsedSubject($comment); // set recipient try { if (version_compare(PHP_VERSION, "5.2.11", ">=") && version_compare(PHP_VERSION, "5.3", "<") || version_compare(PHP_VERSION, "5.3.1", ">=")) { $phpmailer->AddAddress($recipient_email, $recipient_name); } else { // Support: PHP <5.2.11 and PHP 3.0. mail() function on // Windows has bug; doesn't deal with recipient name // correctly. See https://bugs.php.net/bug.php?id=28038 $phpmailer->AddAddress(trim($recipient_email)); } } catch (phpmailerException $e) { return FALSE; } // body HTML needs to be cut off at reasonable line length $body_html_wrapped = wordwrap($body_html, 900, "\n", TRUE); // add HTML body and alternative plain text. $phpmailer->Body = $body_html_wrapped; $phpmailer->isHTML(true); $phpmailer->AltBody = $body_plain; $phpmailer->Encoding = "8bit"; $phpmailer->WordWrap = 80; // word wrap the plain text message $phpmailer->CharSet = "UTF-8"; // try to send try { $phpmailer->Send(); } catch (phpmailerException $e) { var_dump($e); return FALSE; } try { } catch (Exception $ex) { } } return TRUE; }
function wp_mail($to, $subject, $message, $headers = '') { global $phpmailer; if ( !is_object( $phpmailer ) ) { require_once(ABSPATH . WPINC . '/class-phpmailer.php'); require_once(ABSPATH . WPINC . '/class-smtp.php'); $phpmailer = new PHPMailer(); } $mail = compact('to', 'subject', 'message', 'headers'); $mail = apply_filters('wp_mail', $mail); extract($mail); if ( $headers == '' ) { $headers = "MIME-Version: 1.0\n" . "From: " . apply_filters('wp_mail_from', "wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']))) . "\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; } $phpmailer->ClearAddresses(); $phpmailer->ClearCCs(); $phpmailer->ClearBCCs(); $phpmailer->ClearReplyTos(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearCustomHeaders(); $phpmailer->FromName = "WordPress"; $phpmailer->AddAddress("$to", ""); $phpmailer->Subject = $subject; $phpmailer->Body = $message; $phpmailer->IsHTML(false); $phpmailer->IsMail(); // set mailer to use php mail() do_action_ref_array('phpmailer_init', array(&$phpmailer)); $mailheaders = (array) explode( "\n", $headers ); foreach ( $mailheaders as $line ) { $header = explode( ":", $line ); switch ( trim( $header[0] ) ) { case "From": $from = trim( str_replace( '"', '', $header[1] ) ); if ( strpos( $from, '<' ) ) { $phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) ); $from = trim( substr( $from, strpos( $from, '<' ) + 1 ) ); $from = str_replace( '>', '', $from ); } else { $phpmailer->FromName = $from; } $phpmailer->From = trim( $from ); break; default: if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' ) $phpmailer->AddCustomHeader( $line ); break; } } $result = @$phpmailer->Send(); return $result; }
/** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received the * email successfully. It just only means that the method used was able to * process the request without any errors. * * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from * creating a from address like 'Name <*****@*****.**>' when both are set. If * just 'wp_mail_from' is set, then just the email address will be used with no * name. * * The default content type is 'text/plain' which does not allow using HTML. * However, you can set the content type of the email by using the * 'wp_mail_content_type' filter. * * If $message is an array, the key of each is used to add as an attachment * with the value used as the body. The 'text/plain' element is used as the * text version of the body, with the 'text/html' element used as the HTML * version of the body. All other types are added as attachments. * * The default charset is based on the charset used on the blog. The charset can * be set using the 'wp_mail_charset' filter. * * @since 1.2.1 * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters. * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address. * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name. * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type. * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to * phpmailer object. * @uses PHPMailer * @ * * @param string|array $to Array or comma-separated list of email addresses to send message. * @param string $subject Email subject * @param string|array $message Message contents * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Optional. Files to attach. * @return bool Whether the email contents were sent successfully. */ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { // Compact the input, apply the filters, and extract them back out extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'))); if (!is_array($attachments)) { $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); } global $phpmailer; // (Re)create it, if it's gone missing if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(true); } // Headers if (empty($headers)) { $headers = array(); } else { if (!is_array($headers)) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers)); } else { $tempheaders = $headers; } $headers = array(); $cc = array(); $bcc = array(); // If it's actually got contents if (!empty($tempheaders)) { // Iterate through the raw headers foreach ((array) $tempheaders as $header) { if (strpos($header, ':') === false) { if (false !== stripos($header, 'boundary=')) { $parts = preg_split('/boundary=/i', trim($header)); $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); } continue; } // Explode them out list($name, $content) = explode(':', trim($header), 2); // Cleanup crew $name = trim($name); $content = trim($content); switch (strtolower($name)) { // Mainly for legacy -- process a From: header if it's there case 'from': if (strpos($content, '<') !== false) { // So... making my life hard again? $from_name = substr($content, 0, strpos($content, '<') - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); $from_email = substr($content, strpos($content, '<') + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email); } else { $from_email = trim($content); } break; case 'content-type': if (is_array($message)) { // Multipart email, ignore the content-type header break; } if (strpos($content, ';') !== false) { list($type, $charset) = explode(';', $content); $content_type = trim($type); if (false !== stripos($charset, 'charset=')) { $charset = trim(str_replace(array('charset=', '"'), '', $charset)); } elseif (false !== stripos($charset, 'boundary=')) { $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset)); $charset = ''; } } else { $content_type = trim($content); } break; case 'cc': $cc = array_merge((array) $cc, explode(',', $content)); break; case 'bcc': $bcc = array_merge((array) $bcc, explode(',', $content)); break; default: // Add it to our grand headers array $headers[trim($name)] = trim($content); break; } } } } // Empty out the values that may be set $phpmailer->ClearAddresses(); $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearBCCs(); $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if (!isset($from_name)) { $from_name = 'WordPress'; } /* If we don't have an email from the input headers default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist but * there's no easy alternative. Defaulting to admin_email might appear to be another * option but some hosts may refuse to relay mail from an unknown domain. See * http://trac.wordpress.org/ticket/5007. */ if (!isset($from_email)) { // Get the site domain and get rid of www. $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $from_email = 'wordpress@' . $sitename; } // Plugin authors can override the potentially troublesome default $phpmailer->From = apply_filters('wp_mail_from', $from_email); $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name); // Set destination addresses if (!is_array($to)) { $to = explode(',', $to); } foreach ((array) $to as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddAddress(trim($recipient), $recipient_name); } catch (phpmailerException $e) { continue; } } // If we don't have a charset from the input headers if (!isset($charset)) { $charset = get_bloginfo('charset'); } // Set the content-type and charset $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); // Set mail's subject and body $phpmailer->Subject = $subject; if (is_string($message)) { $phpmailer->Body = $message; // Set Content-Type and charset // If we don't have a content-type from the input headers if (!isset($content_type)) { $content_type = 'text/plain'; } $content_type = apply_filters('wp_mail_content_type', $content_type); $phpmailer->ContentType = $content_type; // Set whether it's plaintext, depending on $content_type if ('text/html' == $content_type) { $phpmailer->IsHTML(true); } // For backwards compatibility, new multipart emails should use // the array style $message. This never really worked well anyway if (false !== stripos($content_type, 'multipart') && !empty($boundary)) { $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary)); } } elseif (is_array($message)) { foreach ($message as $type => $bodies) { foreach ((array) $bodies as $body) { if ($type === 'text/html') { $phpmailer->Body = $body; } elseif ($type === 'text/plain') { $phpmailer->AltBody = $body; } else { $phpmailer->AddAttachment($body, '', 'base64', $type); } } } } // Add any CC and BCC recipients if (!empty($cc)) { foreach ((array) $cc as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddCc(trim($recipient), $recipient_name); } catch (phpmailerException $e) { continue; } } } if (!empty($bcc)) { foreach ((array) $bcc as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.+)\\s?<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddBcc(trim($recipient), $recipient_name); } catch (phpmailerException $e) { continue; } } } // Set to use PHP's mail() $phpmailer->IsMail(); // Set custom headers if (!empty($headers)) { foreach ((array) $headers as $name => $content) { $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } } if (!empty($attachments)) { foreach ($attachments as $attachment) { try { $phpmailer->AddAttachment($attachment); } catch (phpmailerException $e) { continue; } } } do_action_ref_array('phpmailer_init', array(&$phpmailer)); // Send! try { $phpmailer->Send(); } catch (phpmailerException $e) { return false; } return true; }
/** * This function mails a text $body to the recipient $to. * You can use more than one recipient when using a semikolon separated string with recipients. * If you send several emails at once please supply an email object so that it can be re-used over and over. Especially with SMTP connections this speeds up things by 200%. * If you supply an email object Do not forget to close the mail connection by calling $mail->SMTPClose(); * * @param mixed $mail This is an PHPMailer object. If null, one will be created automatically and unset afterwards. If supplied it won't be unset. * @param string $body Body text of the email in plain text or HTML * @param mixed $subject Email subject * @param mixed $to * @param mixed $from * @param mixed $sitename * @param mixed $ishtml * @param mixed $bouncemail * @param mixed $attachment * @return bool If successful returns true */ function SendEmailMessage($mail, $body, $subject, $to, $from, $sitename, $ishtml = false, $bouncemail = null, $attachment = null, $customheaders = "") { global $emailmethod, $emailsmtphost, $emailsmtpuser, $emailsmtppassword, $defaultlang, $emailsmtpdebug; global $rootdir, $maildebug, $maildebugbody, $emailsmtpssl, $clang, $demoModeOnly, $emailcharset; if (!is_array($customheaders) && $customheaders == '') { $customheaders = array(); } if ($demoModeOnly == true) { $maildebug = $clang->gT('Email was not sent because demo-mode is activated.'); $maildebugbody = ''; return false; } if (is_null($bouncemail)) { $sender = $from; } else { $sender = $bouncemail; } $bUnsetEmail = false; if (is_null($mail)) { $bUnsetEmail = true; $mail = new PHPMailer(); } else { $mail->SMTPKeepAlive = true; } if (!$mail->SetLanguage($defaultlang, $rootdir . '/classes/phpmailer/language/')) { $mail->SetLanguage('en', $rootdir . '/classes/phpmailer/language/'); } $mail->CharSet = $emailcharset; if (isset($emailsmtpssl) && trim($emailsmtpssl) !== '' && $emailsmtpssl !== 0) { if ($emailsmtpssl === 1) { $mail->SMTPSecure = "ssl"; } else { $mail->SMTPSecure = $emailsmtpssl; } } $fromname = ''; $fromemail = $from; if (strpos($from, '<')) { $fromemail = substr($from, strpos($from, '<') + 1, strpos($from, '>') - 1 - strpos($from, '<')); $fromname = trim(substr($from, 0, strpos($from, '<') - 1)); } $sendername = ''; $senderemail = $sender; if (strpos($sender, '<')) { $senderemail = substr($sender, strpos($sender, '<') + 1, strpos($sender, '>') - 1 - strpos($sender, '<')); $sendername = trim(substr($sender, 0, strpos($sender, '<') - 1)); } switch ($emailmethod) { case "qmail": $mail->IsQmail(); break; case "smtp": $mail->IsSMTP(); if ($emailsmtpdebug > 0) { $mail->SMTPDebug = true; } if (strpos($emailsmtphost, ':') > 0) { $mail->Host = substr($emailsmtphost, 0, strpos($emailsmtphost, ':')); $mail->Port = substr($emailsmtphost, strpos($emailsmtphost, ':') + 1); } else { $mail->Host = $emailsmtphost; } $mail->Username = $emailsmtpuser; $mail->Password = $emailsmtppassword; if (trim($emailsmtpuser) != "") { $mail->SMTPAuth = true; } break; case "sendmail": $mail->IsSendmail(); break; default: //Set to the default value to rule out incorrect settings. $emailmethod = "mail"; $mail->IsMail(); } $mail->SetFrom($fromemail, $fromname); $mail->Sender = $senderemail; // Sets Return-Path for error notifications $toemails = explode(";", $to); foreach ($toemails as $singletoemail) { if (strpos($singletoemail, '<')) { $toemail = substr($singletoemail, strpos($singletoemail, '<') + 1, strpos($singletoemail, '>') - 1 - strpos($singletoemail, '<')); $toname = trim(substr($singletoemail, 0, strpos($singletoemail, '<') - 1)); $mail->AddAddress($toemail, $toname); } else { $mail->AddAddress($singletoemail); } } if (is_array($customheaders)) { foreach ($customheaders as $key => $val) { $mail->AddCustomHeader($val); } } $mail->AddCustomHeader("X-Surveymailer: {$sitename} Emailer (LimeSurvey.sourceforge.net)"); if (get_magic_quotes_gpc() != "0") { $body = stripcslashes($body); } if ($ishtml) { $mail->IsHTML(true); $mail->Body = $body; $mail->AltBody = trim(strip_tags(html_entity_decode($body, ENT_QUOTES, 'UTF-8'))); } else { $mail->IsHTML(false); $mail->Body = $body; } // add the attachment if there is one if (!is_null($attachment)) { $mail->AddAttachment($attachment); } if (trim($subject) != '') { $mail->Subject = "=?{$emailcharset}?B?" . base64_encode($subject) . "?="; } if ($emailsmtpdebug > 0) { ob_start(); } $sent = $mail->Send(); $maildebug = $mail->ErrorInfo; if ($emailsmtpdebug > 0) { $maildebug .= '<li>' . $clang->gT('SMTP debug output:') . '</li><pre>' . strip_tags(ob_get_contents()) . '</pre>'; ob_end_clean(); } $maildebugbody = $mail->Body; $mail->ClearAddresses(); $mail->ClearCustomHeaders(); if ($bUnsetEmail) { unset($mail); } return $sent; }
function mail($to, $subject, $message, $headers = null) { $this->mail_last_error = ''; $this->logger->debug('mail> To: ' . $to); $this->logger->debug('mail> Subject: ' . $subject); if (empty($subject)) { $this->logger->debug('mail> Subject empty, skipped'); return true; } // Message carrige returns and line feeds clean up if (!is_array($message)) { $message = str_replace("\r\n", "\n", $message); $message = str_replace("\r", "\n", $message); $message = str_replace("\n", "\r\n", $message); } else { if (!empty($message['text'])) { $message['text'] = str_replace("\r\n", "\n", $message['text']); $message['text'] = str_replace("\r", "\n", $message['text']); $message['text'] = str_replace("\n", "\r\n", $message['text']); } if (!empty($message['html'])) { $message['html'] = str_replace("\r\n", "\n", $message['html']); $message['html'] = str_replace("\r", "\n", $message['html']); $message['html'] = str_replace("\n", "\r\n", $message['html']); } } if ($this->mail_method != null) { return call_user_func($this->mail_method, $to, $subject, $message, $headers); } if ($this->mailer == null) { $this->mailer_init(); } if ($this->mailer == null) { // If still null, we need to use wp_mail()... $headers = array(); $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-Type: text/html;charset=UTF-8'; $headers[] = 'From: ' . $this->options['sender_name'] . ' <' . $this->options['sender_email'] . '>'; if (!empty($this->options['return_path'])) { $headers[] = 'Return-Path: ' . $this->options['return_path']; } if (!empty($this->options['reply_to'])) { $headers[] = 'Reply-To: ' . $this->options['reply_to']; } if (!is_array($message)) { $headers[] = 'Content-Type: text/html;charset=UTF-8'; $body = $message; } else { // Only html is present? if (!empty($message['html'])) { $headers[] = 'Content-Type: text/html;charset=UTF-8'; $body = $message['html']; } else { if (!empty($message['text'])) { $headers[] = 'Content-Type: text/plain;charset=UTF-8'; $this->mailer->IsHTML(false); $body = $message['text']; } } } $r = wp_mail($to, $subject, $body, $headers); if (!$r) { $last_error = error_get_last(); if (is_array($last_error)) { $this->mail_last_error = $last_error['message']; } } return $r; } // Simple message is asumed to be html if (!is_array($message)) { $this->mailer->IsHTML(true); $this->mailer->Body = $message; } else { // Only html is present? if (empty($message['text'])) { $this->mailer->IsHTML(true); $this->mailer->Body = $message['html']; } else { if (empty($message['html'])) { $this->mailer->IsHTML(false); $this->mailer->Body = $message['text']; } else { $this->mailer->IsHTML(true); $this->mailer->Body = $message['html']; $this->mailer->AltBody = $message['text']; } } } $this->mailer->Subject = $subject; $this->mailer->ClearCustomHeaders(); if (!empty($headers)) { foreach ($headers as $key => $value) { $this->mailer->AddCustomHeader($key . ': ' . $value); } } $this->mailer->ClearAddresses(); $this->mailer->AddAddress($to); $this->mailer->Send(); if ($this->mailer->IsError()) { $this->mail_last_error = $this->mailer->ErrorInfo; $this->logger->error('mail> ' . $this->mailer->ErrorInfo); // If the error is due to SMTP connection, the mailer cannot be reused since it does not clean up the connection // on error. $this->mailer = null; return false; } return true; }
function osc_sendMail($params) { // DO NOT send mail if it's a demo if (defined('DEMO')) { return false; } $mail = new PHPMailer(true); $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearAttachments(); $mail->ClearBCCs(); $mail->ClearCCs(); $mail->ClearCustomHeaders(); $mail->ClearReplyTos(); $mail = osc_apply_filter('init_send_mail', $mail, $params); if (osc_mailserver_pop()) { require_once osc_lib_path() . 'phpmailer/class.pop3.php'; $pop = new POP3(); $pop3_host = osc_mailserver_host(); if (array_key_exists('host', $params)) { $pop3_host = $params['host']; } $pop3_port = osc_mailserver_port(); if (array_key_exists('port', $params)) { $pop3_port = $params['port']; } $pop3_username = osc_mailserver_username(); if (array_key_exists('username', $params)) { $pop3_username = $params['username']; } $pop3_password = osc_mailserver_password(); if (array_key_exists('password', $params)) { $pop3_password = $params['password']; } $pop->Authorise($pop3_host, $pop3_port, 30, $pop3_username, $pop3_password, 0); } if (osc_mailserver_auth()) { $mail->IsSMTP(); $mail->SMTPAuth = true; } else { if (osc_mailserver_pop()) { $mail->IsSMTP(); } } $smtpSecure = osc_mailserver_ssl(); if (array_key_exists('password', $params)) { $smtpSecure = $params['ssl']; } if ($smtpSecure != '') { $mail->SMTPSecure = $smtpSecure; } $stmpUsername = osc_mailserver_username(); if (array_key_exists('username', $params)) { $stmpUsername = $params['username']; } if ($stmpUsername != '') { $mail->Username = $stmpUsername; } $smtpPassword = osc_mailserver_password(); if (array_key_exists('password', $params)) { $smtpPassword = $params['password']; } if ($smtpPassword != '') { $mail->Password = $smtpPassword; } $smtpHost = osc_mailserver_host(); if (array_key_exists('host', $params)) { $smtpHost = $params['host']; } if ($smtpHost != '') { $mail->Host = $smtpHost; } $smtpPort = osc_mailserver_port(); if (array_key_exists('port', $params)) { $smtpPort = $params['port']; } if ($smtpPort != '') { $mail->Port = $smtpPort; } $from = osc_mailserver_mail_from(); if (empty($from)) { $from = 'osclass@' . osc_get_domain(); if (array_key_exists('from', $params)) { $from = $params['from']; } } $from_name = osc_mailserver_name_from(); if (empty($from_name)) { $from_name = osc_page_title(); if (array_key_exists('from_name', $params)) { $from_name = $params['from_name']; } } $mail->From = osc_apply_filter('mail_from', $from, $params); $mail->FromName = osc_apply_filter('mail_from_name', $from_name, $params); $to = $params['to']; $to_name = ''; if (array_key_exists('to_name', $params)) { $to_name = $params['to_name']; } if (!is_array($to)) { $to = array($to => $to_name); } foreach ($to as $to_email => $to_name) { try { $mail->addAddress($to_email, $to_name); } catch (phpmailerException $e) { continue; } } if (array_key_exists('add_bcc', $params)) { if (!is_array($params['add_bcc']) && $params['add_bcc'] != '') { $params['add_bcc'] = array($params['add_bcc']); } foreach ($params['add_bcc'] as $bcc) { try { $mail->AddBCC($bcc); } catch (phpmailerException $e) { continue; } } } if (array_key_exists('reply_to', $params)) { try { $mail->AddReplyTo($params['reply_to']); } catch (phpmailerException $e) { //continue; } } $mail->Subject = $params['subject']; $mail->Body = $params['body']; if (array_key_exists('attachment', $params)) { if (!is_array($params['attachment']) || isset($params['attachment']['path'])) { $params['attachment'] = array($params['attachment']); } foreach ($params['attachment'] as $attachment) { try { if (is_array($attachment)) { if (isset($attachment['path']) && isset($attachment['name'])) { $mail->AddAttachment($attachment['path'], $attachment['name']); } } else { $mail->AddAttachment($attachment); } } catch (phpmailerException $e) { continue; } } } $mail->CharSet = 'utf-8'; $mail->IsHTML(true); $mail = osc_apply_filter('pre_send_mail', $mail, $params); // send email! try { $mail->Send(); } catch (phpmailerException $e) { return false; } return true; }
public function send_email_campaign($sender_data, $receiver_data, $template_data, $user_config) { $this->load->library('My_PHPMailer'); $setup = array("smtp_host" => $user_config['smtp_host'], "smtp_port" => $user_config['smtp_port'], "smtp_protocol" => "TLS", "smtp_auth" => true, "smtp_username" => $user_config['smtp_username'], "smtp_password" => $user_config['smtp_password']); $mail = new PHPMailer(); $mail->XMailer = 'PHP '; $mail->CharSet = 'UTF-8'; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $setup['smtp_host']; // Specify main and backup SMTP servers 'smtp1.example.com;smtp2.example.com' $mail->SMTPAuth = $setup['smtp_auth'] ? true : false; // Enable SMTP authentication $mail->Username = $setup['smtp_username']; // SMTP username $mail->Password = $setup['smtp_password']; // SMTP password $mail->SMTPSecure = $setup['smtp_protocol']; // Enable TLS encryption, `ssl` also accepted $mail->Port = $setup['smtp_port']; // TCP port to connect to $mail->ClearAllRecipients(); $mail->ClearAddresses(); $mail->ClearCCs(); $mail->ClearBCCs(); $mail->ClearReplyTos(); $mail->ClearAttachments(); $mail->ClearCustomHeaders(); $mail->From = $sender_data['email']; $mail->FromName = $sender_data['name']; $mail->addAddress($receiver_data['email'], $receiver_data['name']); // Add a recipient $mail->addReplyTo($sender_data['email'], ''); $mail->isHTML(true); // Set email format to HTML $body = $this->load->view('email/campaign_email', array('template_data' => $template_data), true); $mail->Subject = $template_data['subject']; $mail->Body = $body; // html mail $mail->AltBody = $body; // Plain text mail // For most clients expecting the Priority header: // 1 = High, 2 = Medium, 3 = Low $mail->Priority = 1; // MS Outlook custom header // May set to "Urgent" or "Highest" rather than "High" $mail->AddCustomHeader("X-MSMail-Priority: High"); // Not sure if Priority will also set the Importance header: $mail->AddCustomHeader("Importance: High"); $mail->AddCustomHeader("X-Sender: <{''}>\n"); $mail->addCustomHeader("List-Unsubscribe", "<mailto:unsubscribe@digibuzz24.net/unsubscribe.php?email='" . $sender_data['email'] . "'>"); $mail->addCustomHeader("List-Subscribe", "<mailto:subscribe@digibuzz24.net/subscribe.php?email='" . $sender_data['email'] . "'>"); $mail->addCustomHeader("List-Owner", "<mailto:admin@digibuzz24.net>"); // Uncomment this if ($mail->send()) { return 'ok'; } else { //echo 'Mailer Error: ' . $mail->ErrorInfo; exit; return 'error'; } }
/** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received the * email successfully. It just only means that the method used was able to * process the request without any errors. * * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from * creating a from address like 'Name <*****@*****.**>' when both are set. If * just 'wp_mail_from' is set, then just the email address will be used with no * name. * * The default content type is 'text/plain' which does not allow using HTML. * However, you can set the content type of the email by using the * 'wp_mail_content_type' filter. * * The default charset is based on the charset used on the blog. The charset can * be set using the 'wp_mail_charset' filter. * * @since 1.2.1 * * @uses PHPMailer * * @param string|array $to Array or comma-separated list of email addresses to send message. * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Optional. Files to attach. * @return bool Whether the email contents were sent successfully. */ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { // Compact the input, apply the filters, and extract them back out /** * Filter the wp_mail() arguments. * * @since 2.2.0 * * @param array $args A compacted array of wp_mail() arguments, including the "to" email, * subject, message, headers, and attachments values. */ $atts = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')); if (isset($atts['to'])) { $to = $atts['to']; } if (isset($atts['subject'])) { $subject = $atts['subject']; } if (isset($atts['message'])) { $message = $atts['message']; } if (isset($atts['headers'])) { $headers = $atts['headers']; } if (isset($atts['attachments'])) { $attachments = $atts['attachments']; } if (!is_array($attachments)) { $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); } global $phpmailer; // (Re)create it, if it's gone missing if (!$phpmailer instanceof PHPMailer) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(true); } // Headers if (empty($headers)) { $headers = array(); } else { if (!is_array($headers)) { // Explode the headers out, so this function can take both // string headers and an array of headers. $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers)); } else { $tempheaders = $headers; } $headers = array(); $cc = array(); $bcc = array(); // If it's actually got contents if (!empty($tempheaders)) { // Iterate through the raw headers foreach ((array) $tempheaders as $header) { if (strpos($header, ':') === false) { if (false !== stripos($header, 'boundary=')) { $parts = preg_split('/boundary=/i', trim($header)); $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); } continue; } // Explode them out list($name, $content) = explode(':', trim($header), 2); // Cleanup crew $name = trim($name); $content = trim($content); switch (strtolower($name)) { // Mainly for legacy -- process a From: header if it's there case 'from': $bracket_pos = strpos($content, '<'); if ($bracket_pos !== false) { // Text before the bracketed email is the "From" name. if ($bracket_pos > 0) { $from_name = substr($content, 0, $bracket_pos - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); } $from_email = substr($content, $bracket_pos + 1); $from_email = str_replace('>', '', $from_email); $from_email = trim($from_email); // Avoid setting an empty $from_email. } elseif ('' !== trim($content)) { $from_email = trim($content); } break; case 'content-type': if (strpos($content, ';') !== false) { list($type, $charset_content) = explode(';', $content); $content_type = trim($type); if (false !== stripos($charset_content, 'charset=')) { $charset = trim(str_replace(array('charset=', '"'), '', $charset_content)); } elseif (false !== stripos($charset_content, 'boundary=')) { $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content)); $charset = ''; } // Avoid setting an empty $content_type. } elseif ('' !== trim($content)) { $content_type = trim($content); } break; case 'cc': $cc = array_merge((array) $cc, explode(',', $content)); break; case 'bcc': $bcc = array_merge((array) $bcc, explode(',', $content)); break; default: // Add it to our grand headers array $headers[trim($name)] = trim($content); break; } } } } // Empty out the values that may be set $phpmailer->ClearAllRecipients(); $phpmailer->ClearAttachments(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); // From email and name // If we don't have a name from the input headers if (!isset($from_name)) { $from_name = 'WordPress'; } /* If we don't have an email from the input headers default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist but * there's no easy alternative. Defaulting to admin_email might appear to be another * option but some hosts may refuse to relay mail from an unknown domain. See * https://core.trac.wordpress.org/ticket/5007. */ if (!isset($from_email)) { // Get the site domain and get rid of www. $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $from_email = 'wordpress@' . $sitename; } /** * Filter the email address to send from. * * @since 2.2.0 * * @param string $from_email Email address to send from. */ $phpmailer->From = apply_filters('wp_mail_from', $from_email); /** * Filter the name to associate with the "from" email address. * * @since 2.3.0 * * @param string $from_name Name associated with the "from" email address. */ $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name); // Set destination addresses if (!is_array($to)) { $to = explode(',', $to); } foreach ((array) $to as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddAddress($recipient, $recipient_name); } catch (phpmailerException $e) { continue; } } // Set mail's subject and body $phpmailer->Subject = $subject; $phpmailer->Body = $message; // Add any CC and BCC recipients if (!empty($cc)) { foreach ((array) $cc as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddCc($recipient, $recipient_name); } catch (phpmailerException $e) { continue; } } } if (!empty($bcc)) { foreach ((array) $bcc as $recipient) { try { // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>" $recipient_name = ''; if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { if (count($matches) == 3) { $recipient_name = $matches[1]; $recipient = $matches[2]; } } $phpmailer->AddBcc($recipient, $recipient_name); } catch (phpmailerException $e) { continue; } } } // Set to use PHP's mail() $phpmailer->IsMail(); // Set Content-Type and charset // If we don't have a content-type from the input headers if (!isset($content_type)) { $content_type = 'text/plain'; } /** * Filter the wp_mail() content type. * * @since 2.3.0 * * @param string $content_type Default wp_mail() content type. */ $content_type = apply_filters('wp_mail_content_type', $content_type); $phpmailer->ContentType = $content_type; // Set whether it's plaintext, depending on $content_type if ('text/html' == $content_type) { $phpmailer->IsHTML(true); } // If we don't have a charset from the input headers if (!isset($charset)) { $charset = get_bloginfo('charset'); } // Set the content-type and charset /** * Filter the default wp_mail() charset. * * @since 2.3.0 * * @param string $charset Default email charset. */ $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); // Set custom headers if (!empty($headers)) { foreach ((array) $headers as $name => $content) { $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); } if (false !== stripos($content_type, 'multipart') && !empty($boundary)) { $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary)); } } if (!empty($attachments)) { foreach ($attachments as $attachment) { try { $phpmailer->AddAttachment($attachment); } catch (phpmailerException $e) { continue; } } } /** * Fires after PHPMailer is initialized. * * @since 2.2.0 * * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference. */ do_action_ref_array('phpmailer_init', array(&$phpmailer)); // Send! try { return $phpmailer->Send(); } catch (phpmailerException $e) { return false; } }
$mail->AddAddress($to_email_id, "WeMakeScholars"); //$mail->IsSMTP(); $mail->Mailer = "mail"; $mail->Host = "166.62.28.80"; $mail->Port = 25; if (!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearAttachments(); $mail->ClearBCCs(); $mail->ClearCCs(); $mail->ClearCustomHeaders(); $query1 = "UPDATE registration set weeklynewsletteremailstatus=1 where email_id=? "; if (!($stmt1 = $mysqli->prepare($query1))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; exit; } $stmt1->bind_param("s", $email_id); if (!$stmt1->execute()) { echo "Execute failed: (" . $stmt1->errno . ") " . $stmt1->error; exit; } $stmt1->close(); } $stmt->close(); Header("Location:resetflag.php"); exit;
/** * Retrieve get PHPMailer object * @return PHPMailer */ function dhvc_form_phpmailer() { if (!class_exists('PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; } $mailer = new PHPMailer(true); $mailer->ClearAllRecipients(); $mailer->ClearAttachments(); $mailer->ClearCustomHeaders(); $mailer->ClearReplyTos(); $mailer->IsMail(); //$mailer->Mailer = 'mail'; $mailer->CharSet = get_bloginfo('charset'); if (dhvc_form_get_option('email_method', 'default') == 'smtp') { $mailer->IsSMTP(); $smtp_host = dhvc_form_get_option('smtp_host'); $smtp_post = dhvc_form_get_option('smtp_post'); $smtp_username = dhvc_form_get_option('smtp_username'); $smtp_password = dhvc_form_get_option('smtp_password'); $smtp_encryption = dhvc_form_get_option('smtp_encryption'); if (!empty($smtp_host)) { $mailer->Host = $smtp_host; } if (!empty($smtp_post)) { $mailer->Port = $smtp_post; } if (!empty($smtp_username) && !empty($smtp_password)) { $mailer->SMTPAuth = true; $mailer->Username = $smtp_username; $mailer->Password = $smtp_password; } if (in_array($smtp_encryption, array('tls', 'ssl'))) { $mailer->SMTPSecure = $smtp_encryption; } } return $mailer; }