function mailer_to($to, $subject, $body) { require_once "class.phpmailer.php"; $mail3 = new PHPMailer(); $mail3->IsSMTP(); // telling the class to use SMTP $mail3->Host = "mail.pp3.co.id"; // SMTP server $mail3->SMTPAuth = true; // enable SMTP authentication $mail3->SMTPSecure = "ntlm"; // sets the prefix to the servier $mail3->IsHTML(true); $mail3->Username = "******"; // GMAIL username $mail3->Password = "******"; // GMAIL password $mail3->SetFrom('*****@*****.**', 'Subdit. Sistem Informasi Kantor Pusat Pelindo III'); $mail3->AddAddress($to); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: support_si@pp3.co.id <Subdit. Sistem Informasi Kantor Pusat Pelindo III>\r\n"; $mail3->Subject = $subject; $mail3->Body = $body; $mail3->AddCustomHeader($headers); $mail3->WordWrap = 100; if (!$mail3->Send()) { echo 'Email tidak terkirim.'; echo 'Mailer error: ' . $mail3->ErrorInfo; } else { echo 'Email Terkirim.<br>'; } }
/** * Creates new instance of PHPMailer and set default options from config * @api * @throws ComponentException * @throws \phpmailerException * @return \PHPMailer */ public function create() { // can initial, can't use if (!class_exists('\\PHPMailer')) { throw new ComponentException("PHPMailer library is required for `Bluz\\Mailer` package. <br/>\n" . "Read more: <a href='https://github.com/bluzphp/framework/wiki/Mailer'>" . "https://github.com/bluzphp/framework/wiki/Mailer</a>"); } $mail = new \PHPMailer(); $mail->WordWrap = 920; // RFC 2822 Compliant for Max 998 characters per line $fromEmail = $this->getOption('from', 'email'); $fromName = $this->getOption('from', 'name') ?: ''; // setup options from config $mail->SetFrom($fromEmail, $fromName, false); // setup options if ($settings = $this->getOption('settings')) { foreach ($settings as $name => $value) { $mail->set($name, $value); } } // setup custom headers if ($headers = $this->getOption('headers')) { foreach ($headers as $header => $value) { $mail->AddCustomHeader($header, $value); } } return $mail; }
/** * 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'); }
/** * Extended AddCustomHeader function in order to stop duplicate * message-ids * http://tracker.moodle.org/browse/MDL-3681 */ public function AddCustomHeader($custom_header) { if (preg_match('/message-id:(.*)/i', $custom_header, $matches)) { $this->MessageID = $matches[1]; return true; } else { return parent::AddCustomHeader($custom_header); } }
function send($o, $to, $from, $subject, $body, $headers) { $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->SMTPDebug = 0; // enables SMTP debug information (for testing) $mail->SMTPAuth = $this->api->getConfig("tmail/phpmailer/username", null) ? true : false; // enable SMTP authentication $mail->Host = $this->api->getConfig("tmail/smtp/host"); $mail->Port = $this->api->getConfig("tmail/smtp/port"); $mail->Username = $this->api->getConfig("tmail/phpmailer/username", null); $mail->Password = $this->api->getConfig("tmail/phpmailer/password", null); $mail->SMTPSecure = 'tls'; $mail->AddReplyTo($this->api->getConfig("tmail/phpmailer/reply_to"), $this->api->getConfig("tmail/phpmailer/reply_to_name")); $mail->AddAddress($to); $mail->Subject = $subject; $mail->MsgHTML($body); $mail->AltBody = null; $mail->IsHTML(true); $bcc = $this->api->getConfig("tmail/phpmailer/bcc", null); if ($bcc) { $bcc_name = $this->api->getConfig("tmail/phpmailer/bcc_name", null); $mail->AddBCC($bcc, $bcc_name); } $internal_header_map = array("Content-Type" => "ContentType"); $void_headers = array("MIME-Version"); $fromAdded = false; foreach (explode("\n", $headers) as $h) { if (preg_match("/^(.*?):(.*)\$/", $h, $t)) { if (strtolower($t[1]) == "from" && $t[2]) { $mail->SetFrom($t[2]); $fromAdded = true; continue; } if (isset($internal_header_map[$t[1]])) { $key = $internal_header_map[$t[1]]; $mail->{$key} = $t[2]; continue; } else { if (in_array($t[1], $void_headers)) { continue; } } } $mail->AddCustomHeader($h); } if (!$fromAdded) { $mail->SetFrom($this->api->getConfig("tmail/phpmailer/from"), $from ? "" : $this->api->getConfig("tmail/phpmailer/from_name")); $mail->AddReplyTo($this->api->getConfig("tmail/phpmailer/reply_to"), $this->api->getConfig("tmail/phpmailer/reply_to_name")); } $mail->Send(); }
public function mail($to, $subj, $body, $headers = false, $params = false) { $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "mail.inversiondesigns.com"; // specify main and backup server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "******"; // SMTP username $mail->Password = "******"; // SMTP password $mail->AddAddress($to); if (is_string($headers)) { $headers = explode("\n", $headers); foreach ($headers as $header) { $h = explode(":", $header, 2); if (stripos($h[0], "From") !== false) { $from = $h[1]; if (stripos($from, "<") !== false) { $start = strpos($from, "<") + 1; $mail->From = substr($from, $start, strpos($from, ">") - $start); $mail->FromName = substr($from, 0, strpos($from, "<")); } else { $mail->From = $h[1]; $mail->FromName = $h[1]; } } else { $mail->AddCustomHeader(trim($header)); } } } else { $mail->From = "*****@*****.**"; $mail->FromName = "Inversion Bot"; $mail->AddReplyTo("*****@*****.**", "No Reply"); } //$mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = $subj; $mail->Body = $body; $mail->AltBody = strip_tags($body); $result = $mail->Send(); $mail->close(); return $result; }
function phpmailer_init_smtp(PHPMailer $phpmailer) { if (!get_option('mailjet_enabled') || 0 == get_option('mailjet_enabled')) { return; } $phpmailer->Mailer = 'smtp'; $phpmailer->SMTPSecure = get_option('mailjet_ssl'); $phpmailer->Host = MJ_HOST; $phpmailer->Port = get_option('mailjet_port'); $phpmailer->SMTPAuth = TRUE; $phpmailer->Username = get_option('mailjet_username'); $phpmailer->Password = get_option('mailjet_password'); $from_email = get_option('mailjet_from_email') ? get_option('mailjet_from_email') : get_option('admin_email'); $phpmailer->From = $from_email; $phpmailer->Sender = $from_email; $phpmailer->AddCustomHeader(MJ_MAILER); }
/** * 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'); }
public static function sendEmail($vars, $email, $body, $alt, $clicktrack = true) { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Username = CShell::SMTPUN(); $mail->Password = CShell::SMTPPW(); $mail->IsHTML(true); $mail->SetFrom($vars["from"]); $mail->FromName = $vars["name"]; $mail->AddReplyTo($vars["reply"]); $mail->Subject = $vars["subject"]; $mail->MsgHTML($body); $mail->AltBody = $alt; $x_smtpapi = array('category' => array('webinar', $vars['category'])); if (!$clicktrack) { $x_smtpapi['filters'] = array('clicktrack' => array('settings' => array('enable' => 0))); } $blah = 'X-SMTPAPI: ' . json_encode($x_smtpapi); $mail->AddCustomHeader($blah); $mail->AddAddress($email); $response = $mail->Send(); $mail->ClearAddresses(); return $response; }
/** * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully) * Sender name and email can be specified, if not specified * name and email of the platform admin are used * * @author Bert Vanderkimpen ICT&O UGent * @author Yannick Warnier <*****@*****.**> * * @param string name of recipient * @param string email of recipient * @param string email subject * @param string email body * @param string sender name * @param string sender e-mail * @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array data file (path and filename) * @param array data to attach a file (optional) * @param bool True for attaching a embedded file inside content html (optional) * @return returns true if mail was sent * @see class.phpmailer.php */ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $senderName = '', $senderEmail = '', $extra_headers = array(), $data_file = array(), $embedded_image = false, $additionalParameters = array()) { global $platform_email; $mail = new PHPMailer(); $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; $mail->CharSet = $platform_email['SMTP_CHARSET']; // Stay far below SMTP protocol 980 chars limit. $mail->WordWrap = 200; if ($platform_email['SMTP_AUTH']) { $mail->SMTPAuth = 1; $mail->Username = $platform_email['SMTP_USER']; $mail->Password = $platform_email['SMTP_PASS']; } // 5 = low, 1 = high $mail->Priority = 3; $mail->SMTPKeepAlive = true; // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // Error to admin. $mail->AddCustomHeader('Errors-To: ' . $defaultEmail); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultEmail; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultName; // Reply to first if (isset($extra_headers['reply_to'])) { $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); $mail->Sender = $extra_headers['reply_to']['mail']; unset($extra_headers['reply_to']); } $mail->SetFrom($senderEmail, $senderName); $mail->Subject = $subject; $mail->AltBody = strip_tags(str_replace('<br />', "\n", api_html_entity_decode($message))); // Send embedded image. if ($embedded_image) { // Get all images html inside content. preg_match_all("/<img\\s+.*?src=[\"\\']?([^\"\\' >]*)[\"\\']?[^>]*>/i", $message, $m); // Prepare new tag images. $new_images_html = array(); $i = 1; if (!empty($m[1])) { foreach ($m[1] as $image_path) { $real_path = realpath($image_path); $filename = basename($image_path); $image_cid = $filename . '_' . $i; $encoding = 'base64'; $image_type = mime_content_type($real_path); $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); $new_images_html[] = '<img src="cid:' . $image_cid . '" />'; $i++; } } // Replace origin image for new embedded image html. $x = 0; if (!empty($m[0])) { foreach ($m[0] as $orig_img) { $message = str_replace($orig_img, $new_images_html[$x], $message); $x++; } } } $message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message); $mail->Body = '<html><head></head><body>' . $message . '</body></html>'; // Attachment ... if (!empty($data_file)) { $mail->AddAttachment($data_file['path'], $data_file['filename']); } // Only valid addresses are accepted. if (is_array($recipient_email)) { foreach ($recipient_email as $dest) { if (api_valid_email($dest)) { $mail->AddAddress($dest, $recipient_name); } } } else { if (api_valid_email($recipient_email)) { $mail->AddAddress($recipient_email, $recipient_name); } else { return 0; } } if (is_array($extra_headers) && count($extra_headers) > 0) { foreach ($extra_headers as $key => $value) { switch (strtolower($key)) { case 'encoding': case 'content-transfer-encoding': $mail->Encoding = $value; break; case 'charset': $mail->Charset = $value; break; case 'contenttype': case 'content-type': $mail->ContentType = $value; break; default: $mail->AddCustomHeader($key . ':' . $value); break; } } } else { if (!empty($extra_headers)) { $mail->AddCustomHeader($extra_headers); } } // WordWrap the html body (phpMailer only fixes AltBody) FS#2988 $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap); // Send the mail message. if (!$mail->Send()) { error_log('ERROR: mail not sent to ' . $recipient_name . ' (' . $recipient_email . ') because of ' . $mail->ErrorInfo . '<br />'); return 0; } $plugin = new AppPlugin(); $installedPluginsList = $plugin->getInstalledPluginListObject(); foreach ($installedPluginsList as $installedPlugin) { if ($installedPlugin->isMailPlugin and array_key_exists("smsType", $additionalParameters)) { $clockworksmsObject = new Clockworksms(); $clockworksmsObject->send($additionalParameters); } } // Clear all the addresses. $mail->ClearAddresses(); return 1; }
/** * 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; }
function send_mail($rec_email, $subject, $message, $IsHtml = false, $cc = array(), $bcc = array()) { global $THIS_BASEPATH, $btit_settings; if (!method_exists('PHPMailer', 'IsMail')) { include $THIS_BASEPATH . '/phpmailer/class.phpmailer.php'; } $mail = new PHPMailer(); if ($btit_settings['mail_type'] == 'php') { $mail->IsMail(); # send via mail if (!empty($cc)) { $mail->AddCustomHeader('Cc: ' . implode(',', $cc)); } if (!empty($bcc)) { $mail->AddCustomHeader('Bcc: ' . implode(',', $bcc)); } } else { $mail->IsSMTP(); # send via SMTP $mail->Host = $btit_settings['smtp_server']; # SMTP servers $mail->Port = $btit_settings['smtp_port']; # SMTP port $mail->SMTPAuth = true; # turn on SMTP authentication $mail->Username = $btit_settings['smtp_username']; # SMTP username $mail->Password = $btit_settings['smtp_password']; # SMTP password if (!empty($cc)) { foreach ($cc as $carbon_copy) { $mail->AddCC($carbon_copy[0], $carbon_copy[0]); } } if (!empty($bcc)) { foreach ($bcc as $blind_carbon_copy) { $mail->AddBCC($blind_carbon_copy[0], $blind_carbon_copy[0]); } } } $mail->From = $btit_settings['email']; $mail->FromName = $btit_settings['name']; $mail->CharSet = $btit_settings['default_charset']; $mail->IsHTML($IsHtml); $mail->AddAddress($rec_email); $mail->AddReplyTo($btit_settings['email'], $btit_settings['name']); $mail->Subject = $subject; $mail->Body = $message; return $mail->Send() ? true : $mail->ErrorInfo; }
/** * Sends email to a list of recipients. * * @param array $mail A mail configuration array. * * Possible configuration elements include: * * • `subject` (string, NOT empty). * • `message` (string, NOT empty). * * • `from_addr` (string, NOT empty). * • `from_name` (string, optional from name). * * • `recipients` (string|array, NOT empty). * Strings may contain multiple email addresses (comma or semicolon separated); which this routine parses into an array. * NOTE: Emails are ALWAYS sent ONE at a time; making the concept of CC/BCC addresses irrelevant. * * • `headers` (string|array, optional). A custom header string, or an array of custom header strings. * All header strings are self-contained. We do NOT support any special array elements here. * Example: `Header: value` (where each string is an email header). * * • `attachments` (string|array, optional). An absolute file path, or an array of absolute file paths. * File paths can be absolute, or relative to the current WordPress® `ABSPATH`; if that is easier. * * Or, this can also be an array of attachment configurations. * Possible attachment configuration elements include. * • `path` (absolute or relative server path to a file, NOT empty). * • `name` (optional string name for this file, defaults to `basename()`). * • `encoding` (optional string encoding type, defaults to `base64`). * • `mime_type` (optional string MIME type, defaults to `application/octet-stream`). * * @return boolean|errors TRUE if mail was sent successfully. * Else this returns an `errors` object instance. * * @throws exception If invalid types are passed through arguments list. * @throws exception If required configuration elements are missing and/or invalid. */ public function send($mail) { $this->check_arg_types('array:!empty', func_get_args()); // Load PHPMailer classes (if NOT already loaded). if (!class_exists('\\PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; } if (!class_exists('\\SMTP')) { require_once ABSPATH . WPINC . '/class-smtp.php'; } $default_mail_args = array('from_addr' => '', 'subject' => '', 'message' => '', 'recipients' => '', 'attachments' => '', 'headers' => '', 'from_name' => ''); $mail = $this->check_extension_arg_types('string:!empty', 'string:!empty', 'string:!empty', array('string:!empty', 'array:!empty'), array('string', 'array'), array('string', 'array'), 'string', $default_mail_args, $mail, 4); $mail['from_addr'] = apply_filters('wp_mail_from', $mail['from_addr']); $mail['from_name'] = apply_filters('wp_mail_from_name', $mail['from_name']); // Recipients are always parsed into an array here. if (!($mail['recipients'] = $this->parse_emails_deep($mail['recipients']))) { throw $this->©exception($this->method(__FUNCTION__) . '#recipients_missing', get_defined_vars(), $this->__('Email failure. Missing and/or invalid `recipients` value.')); } // Possible header(s). if ($this->©string->is_not_empty($mail['headers'])) { $mail['headers'] = array($mail['headers']); } $this->©array->isset_or($mail['headers'], array(), TRUE); // Standardize/validate each header. foreach ($mail['headers'] as $_header) { if (!$this->©string->is_not_empty($_header)) { throw $this->©exception($this->method(__FUNCTION__) . '#header_missing', get_defined_vars(), $this->__('Email failure. Missing and/or invalid `header`.') . ' ' . sprintf($this->__('Got: `%1$s`.'), $this->©var->dump($_header))); } } unset($_header); // Just a little housekeeping. // Possible file attachment(s). if ($this->©string->is_not_empty($mail['attachments'])) { $mail['attachments'] = array($mail['attachments']); } $this->©array->isset_or($mail['attachments'], array(), TRUE); // Standardize/validate each attachment. foreach ($mail['attachments'] as &$_attachment) { if (!is_array($_attachment)) { $_attachment = array('path' => $_attachment); } if (!$this->©string->is_not_empty($_attachment['path'])) { throw $this->©exception($this->method(__FUNCTION__) . '#attachment_path_missing', get_defined_vars(), $this->__('Email failure. Missing and/or invalid attachment `path` value.') . ' ' . sprintf($this->__('Got: `%1$s`.'), $this->©var->dump($_attachment))); } if (!is_file($_attachment['path'])) { // Perhaps relative? if (!is_file(ABSPATH . $_attachment['path'])) { throw $this->©exception($this->method(__FUNCTION__) . '#nonexistent_attachment_path', get_defined_vars(), $this->__('Email failure. Nonexistent attachment `path` value.') . ' ' . sprintf($this->__('Got: `%1$s`.'), $this->©var->dump($_attachment))); } else { $_attachment['path'] = ABSPATH . $_attachment['path']; } } if (!$this->©string->is_not_empty($_attachment['name'])) { $_attachment['name'] = basename($_attachment['path']); } if (!$this->©string->is_not_empty($_attachment['encoding'])) { $_attachment['encoding'] = 'base64'; } // Default encoding. if (!$this->©string->is_not_empty($_attachment['mime_type'])) { $_attachment['mime_type'] = $this->©file->mime_type($_attachment['path']); } } unset($_attachment); // Just a little housekeeping. try { $mailer = new \PHPMailer(TRUE); $mailer->IsMail(); $mailer->SingleTo = TRUE; $mailer->CharSet = 'UTF-8'; $mailer->Subject = $mail['subject']; $mailer->SetFrom($mail['from_addr'], $mail['from_name']); foreach ($mail['recipients'] as $_recipient_addr) { $mailer->AddAddress($_recipient_addr); } unset($_recipient_addr); foreach ($mail['headers'] as $_header) { $mailer->AddCustomHeader($_header); } unset($_header); // Housekeeping. if (!$this->©string->is_html($mail['message'])) { $mail['message'] = nl2br(esc_html($mail['message'])); } $mailer->MsgHTML($mail['message']); foreach ($mail['attachments'] as $_attachment) { $mailer->AddAttachment($_attachment['path'], $_attachment['name'], $_attachment['encoding'], $_attachment['mime_type']); } unset($_attachment); // Housekeeping. if ($this->©option->get('mail.smtp')) { $mailer->IsSMTP(); // Flag for SMTP use in this case. $mailer->SMTPSecure = $this->©option->get('mail.smtp.secure'); $mailer->Host = $this->©option->get('mail.smtp.host'); $mailer->Port = (int) $this->©option->get('mail.smtp.port'); $mailer->SMTPAuth = (bool) $this->©option->get('mail.smtp.username'); $mailer->Username = $this->©option->get('mail.smtp.username'); $mailer->Password = $this->©option->get('mail.smtp.password'); if ($this->©option->get('mail.smtp.force_from') && $this->©option->get('mail.smtp.from_addr')) { $mailer->SetFrom($this->©option->get('mail.smtp.from_addr'), $this->©option->get('mail.smtp.from_name')); } } do_action('phpmailer_init', $mailer); // WP Mail SMTP, and others like it need this. $mailer->Send(); // Send this email message. } catch (\phpmailerException $exception) { return $this->©error($this->method(__FUNCTION__), get_defined_vars(), $exception->getMessage()); } catch (\exception $exception) { return $this->©error($this->method(__FUNCTION__), get_defined_vars(), $exception->getMessage()); } return TRUE; // Default return value. }
/** * this function is a wrapper to the php mail() function so that we can change settings globally * for more info on format="flowed" see: http://www.joeclark.org/ffaq.html * for deatiled info on MIME (RFC 1521) email see: http://www.freesoft.org/CIE/RFC/1521/index.htm */ function pgvMail($to, $from, $subject, $message) { global $PGV_SMTP_ACTIVE, $PGV_SMTP_HOST, $PGV_SMTP_HELO, $PGV_SMTP_FROM_NAME, $PGV_SMTP_PORT, $PGV_SMTP_AUTH, $PGV_SMTP_AUTH_USER, $PGV_SMTP_AUTH_PASS, $PGV_SMTP_SSL; global $pgv_lang, $CHARACTER_SET, $LANGUAGE, $PGV_STORE_MESSAGES, $TEXT_DIRECTION; $mailFormat = "plain"; //$mailFormat = "html"; //$mailFormat = "multipart"; $mailFormatText = "text/plain"; $boundary = "PGV-123454321-PGV"; //unique identifier for multipart $boundary2 = "PGV-123454321-PGV2"; if ($TEXT_DIRECTION == "rtl") { // needed for rtl but we can change this to a global config $mailFormat = "html"; } if ($mailFormat == "html") { $mailFormatText = "text/html"; } else { if ($mailFormat == "multipart") { $mailFormatText = "multipart/related; \n\tboundary=\"{$boundary}\""; //for double display use:multipart/mixed } else { $mailFormatText = "text/plain"; } } $extraHeaders = "From: {$from}\nContent-type: {$mailFormatText};"; if ($mailFormat != "multipart") { $extraHeaders .= "\tcharset=\"{$CHARACTER_SET}\";\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit"; } if ($mailFormat == "html" || $mailFormat == "multipart") { $extraHeaders .= "\nMime-Version: 1.0"; } $extraHeaders .= "\n"; if ($mailFormat == "html") { //wrap message in html $htmlMessage = ""; $htmlMessage .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $htmlMessage .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $htmlMessage .= "<head>"; $htmlMessage .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"; $htmlMessage .= "</head>"; $htmlMessage .= "<body dir=\"{$TEXT_DIRECTION}\"><pre>"; $htmlMessage .= $message; //add message $htmlMessage .= "</pre></body>"; $htmlMessage .= "</html>"; $message = $htmlMessage; } else { if ($mailFormat == "multipart") { //wrap message in html $htmlMessage = "--{$boundary}\n"; $htmlMessage .= "Content-Type: multipart/alternative; \n\tboundary=--{$boundary2}\n\n"; $htmlMessage = "--{$boundary2}\n"; $htmlMessage .= "Content-Type: text/plain; \n\tcharset=\"{$CHARACTER_SET}\";\n\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit\n\n"; $htmlMessage .= $message; $htmlMessage .= "\n\n--{$boundary2}\n"; $htmlMessage .= "Content-Type: text/html; \n\tcharset=\"{$CHARACTER_SET}\";\n\tformat=\"flowed\"\nContent-Transfer-Encoding: 8bit\n\n"; $htmlMessage .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $htmlMessage .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $htmlMessage .= "<head>"; $htmlMessage .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"; $htmlMessage .= "</head>"; $htmlMessage .= "<body dir=\"{$TEXT_DIRECTION}\"><pre>"; $htmlMessage .= $message; //add message $htmlMessage .= "</pre>"; $htmlMessage .= "<img src=\"cid:pgvlogo@pgvserver\" alt=\"\" style=\"border: 0px; display: block; margin-left: auto; margin-right: auto;\" />"; $htmlMessage .= "</body>"; $htmlMessage .= "</html>"; $htmlMessage .= "\n--{$boundary2}--\n"; $htmlMessage .= "\n--{$boundary}\n"; $htmlMessage .= getPgvMailLogo(); $htmlMessage .= "\n\n\n\n--{$boundary}--"; $message = $htmlMessage; } } // if SMTP mail is set active AND we have SMTP settings available, use the PHPMailer classes if ($PGV_SMTP_ACTIVE && ($PGV_SMTP_HOST && $PGV_SMTP_PORT)) { require_once 'includes/class.phpmailer.php'; $mail_object = new PHPMailer(); $mail_object->IsSMTP(); $mail_object->SetLanguage('en', 'languages/'); if ($PGV_SMTP_AUTH && ($PGV_SMTP_AUTH_USER && $PGV_SMTP_AUTH_PASS)) { $mail_object->SMTPAuth = $PGV_SMTP_AUTH; $mail_object->Username = $PGV_SMTP_AUTH_USER; $mail_object->Password = $PGV_SMTP_AUTH_PASS; } if ($PGV_SMTP_SSL == 'ssl') { $mail_object->SMTPSecure = 'ssl'; } else { if ($PGV_SMTP_SSL == 'tls') { $mail_object->SMTPSecure = 'tls'; } } $mail_object->Host = $PGV_SMTP_HOST; $mail_object->Port = $PGV_SMTP_PORT; $mail_object->Hostname = $PGV_SMTP_HELO; $mail_object->From = $from; if (!empty($PGV_SMTP_FROM_NAME) && $from != $PGV_SMTP_AUTH_USER) { $mail_object->FromName = $PGV_SMTP_FROM_NAME; $mail_object->AddAddress($to); } else { $mail_object->FromName = $mail_object->AddAddress($to); } $mail_object->Subject = hex4email($subject, $CHARACTER_SET); $mail_object->ContentType = $mailFormatText; if ($mailFormat != "multipart") { $mail_object->ContentType = $mailFormatText . '; format="flowed"'; $mail_object->CharSet = $CHARACTER_SET; $mail_object->Encoding = '8bit'; } if ($mailFormat == "html" || $mailFormat == "multipart") { $mail_object->AddCustomHeader('Mime-Version: 1.0'); $mail_object->IsHTML(true); } $mail_object->Body = $message; // attempt to send mail if (!$mail_object->Send()) { echo 'Message was not sent.<br />'; echo 'Mailer error: ' . $mail_object->ErrorInfo . '<br />'; return; } else { // SMTP OK return; } } else { // use original PGV mail sending function mail($to, hex4email($subject, $CHARACTER_SET), $message, $extraHeaders); } }
/** * API function to send e-mail message * @param string $args['fromname'] name of the sender * @param string $args['fromaddress'] address of the sender * @param string $args['toname '] name to the recipient * @param string $args['toaddress'] the address of the recipient * @param string $args['replytoname '] name to reply to * @param string $args['replytoaddress'] address to reply to * @param string $args['subject'] message subject * @param string $args['contenttype '] optional contenttype of the mail (default config) * @param string $args['charset'] optional charset of the mail (default config) * @param string $args['encoding'] optional mail encoding (default config) * @param string $args['body'] message body, if altbody is provided then this * is the HTML version of the body * @param string $args['altbody'] alternative plain-text message body, if * specified the e-mail will be sent as multipart/alternative * @param array $args['cc'] addresses to add to the cc list * @param array $args['bcc'] addresses to add to the bcc list * @param array|string $args['headers'] custom headers to add * @param int $args['html'] HTML flag, if altbody is not specified then this * indicates whether body contains HTML or not; if altbody is * specified, then this value is ignored, the body is assumed * to be HTML, and the altbody is assumed to be plain text * @param array $args['attachments'] array of either absolute filenames to attach * to the mail or array of arays in format * array($string,$filename,$encoding,$type) * @param array $args['stringattachments'] array of arrays to treat as attachments, * format array($string,$filename,$encoding,$type) * @param array $args['embeddedimages'] array of absolute filenames to image files * to embed in the mail * @todo Loading of language file based on Zikula language * @return bool true if successful, false otherwise */ public function sendmessage($args) { // Check for installed advanced Mailer module $event = new GenericEvent($this, $args); $this->dispatcher->dispatch('module.mailer.api.sendmessage', $event); if ($event->isPropagationStopped()) { return $event->getData(); } // include php mailer class file require_once \ZIKULA_ROOT . "/system/Mailer/lib/vendor/class.phpmailer.php"; // create new instance of mailer class $mail = new \PHPMailer(); // set default message parameters $mail->PluginDir = "system/Mailer/lib/vendor/"; $mail->ClearAllRecipients(); $mail->ContentType = isset($args['contenttype']) ? $args['contenttype'] : $this->getVar('contenttype'); $mail->CharSet = isset($args['charset']) ? $args['charset'] : $this->getVar('charset'); $mail->Encoding = isset($args['encoding']) ? $args['encoding'] : $this->getVar('encoding'); $mail->WordWrap = $this->getVar('wordwrap'); // load the language file $mail->SetLanguage('en', $mail->PluginDir . 'language/'); // get MTA configuration if ($this->getVar('mailertype') == 4) { $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = $this->getVar('smtpserver'); // specify server $mail->Port = $this->getVar('smtpport'); // specify port } elseif ($this->getVar('mailertype') == 3) { $mail->IsQMail(); // set mailer to use QMail } elseif ($this->getVar('mailertype') == 2) { ini_set("sendmail_from", $args['fromaddress']); $mail->IsSendMail(); // set mailer to use SendMail $mail->Sendmail = $this->getVar('sendmailpath'); // specify Sendmail path } else { $mail->IsMail(); // set mailer to use php mail } // set authentication paramters if required if ($this->getVar('smtpauth') == 1) { $mail->SMTPAuth = true; // turn on SMTP authentication $mail->SMTPSecure = $this->getVar('smtpsecuremethod'); // SSL or TLS $mail->Username = $this->getVar('smtpusername'); // SMTP username $mail->Password = $this->getVar('smtppassword'); // SMTP password } // set HTML mail if required if (isset($args['html']) && is_bool($args['html'])) { $mail->IsHTML($args['html']); // set email format to HTML } else { $mail->IsHTML($this->getVar('html')); // set email format to the default } // set fromname and fromaddress, default to 'sitename' and 'adminmail' config vars $mail->FromName = isset($args['fromname']) && $args['fromname'] ? $args['fromname'] : System::getVar('sitename'); $mail->From = isset($args['fromaddress']) && $args['fromaddress'] ? $args['fromaddress'] : System::getVar('adminmail'); // add any to addresses if (is_array($args['toaddress'])) { $i = 0; foreach ($args['toaddress'] as $toadd) { isset($args['toname'][$i]) ? $toname = $args['toname'][$i] : ($toname = $toadd); $mail->AddAddress($toadd, $toname); $i++; } } else { // $toaddress is not an array -> old logic $toname = ''; if (isset($args['toname'])) { $toname = $args['toname']; } // process multiple names entered in a single field separated by commas (#262) foreach (explode(',', $args['toaddress']) as $toadd) { $mail->AddAddress($toadd, $toname == '' ? $toadd : $toname); } } // if replytoname and replytoaddress have been provided us them // otherwise take the fromaddress, fromname we build earlier if (!isset($args['replytoname']) || empty($args['replytoname'])) { $args['replytoname'] = $mail->FromName; } if (!isset($args['replytoaddress']) || empty($args['replytoaddress'])) { $args['replytoaddress'] = $mail->From; } $mail->AddReplyTo($args['replytoaddress'], $args['replytoname']); // add any cc addresses if (isset($args['cc']) && is_array($args['cc'])) { foreach ($args['cc'] as $email) { if (isset($email['name'])) { $mail->AddCC($email['address'], $email['name']); } else { $mail->AddCC($email['address']); } } } // add any bcc addresses if (isset($args['bcc']) && is_array($args['bcc'])) { foreach ($args['bcc'] as $email) { if (isset($email['name'])) { $mail->AddBCC($email['address'], $email['name']); } else { $mail->AddBCC($email['address']); } } } // add any custom headers if (isset($args['headers']) && is_string($args['headers'])) { $args['headers'] = explode("\n", $args['headers']); } if (isset($args['headers']) && is_array($args['headers'])) { foreach ($args['headers'] as $header) { $mail->AddCustomHeader($header); } } // add message subject and body $mail->Subject = $args['subject']; $mail->Body = $args['body']; if (isset($args['altbody']) && !empty($args['altbody'])) { $mail->AltBody = $args['altbody']; } // add attachments if (isset($args['attachments']) && !empty($args['attachments'])) { foreach ($args['attachments'] as $attachment) { if (is_array($attachment)) { if (count($attachment) != 4) { // skip invalid arrays continue; } $mail->AddAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]); } else { $mail->AddAttachment($attachment); } } } // add string attachments. if (isset($args['stringattachments']) && !empty($args['stringattachments'])) { foreach ($args['stringattachments'] as $attachment) { if (is_array($attachment) && count($attachment) == 4) { $mail->AddStringAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]); } } } // add embedded images if (isset($args['embeddedimages']) && !empty($args['embeddedimages'])) { foreach ($args['embeddedimages'] as $embeddedimage) { $ret = $mail->AddEmbeddedImage($embeddedimage['path'], $embeddedimage['cid'], $embeddedimage['name'], $embeddedimage['encoding'], $embeddedimage['type']); } } // send message if (!$mail->Send()) { // message not send $args['errorinfo'] = $mail->IsError() ? $mail->ErrorInfo : __('Error! An unidentified problem occurred while sending the e-mail message.'); LogUtil::log(__f('Error! A problem occurred while sending an e-mail message from \'%1$s\' (%2$s) to (%3$s) (%4$s) with the subject line \'%5$s\': %6$s', $args)); if (SecurityUtil::checkPermission('Mailer::', '::', ACCESS_ADMIN)) { return LogUtil::registerError($args['errorinfo']); } else { return LogUtil::registerError(__('Error! A problem occurred while sending the e-mail message.')); } } return true; // message sent }
/** * Returns a PHPMailer with everything set except the recipients * * $pMessage['subject'] - The subject * $pMessage['message'] - The HTML body of the message * $pMessage['alt_message'] - The Non HTML body of the message */ function transport_email_build_mailer($pMessage) { global $gBitSystem, $gBitLanguage; require_once UTIL_PKG_PATH . 'phpmailer/class.phpmailer.php'; $mailer = new PHPMailer(); $mailer->From = !empty($pMessage['from']) ? $pMessage['from'] : $gBitSystem->getConfig('bitmailer_sender_email', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN'])); $mailer->FromName = !empty($pMessage['from_name']) ? $pMessage['from_name'] : $gBitSystem->getConfig('bitmailer_from', $gBitSystem->getConfig('site_title')); if (!empty($pMessage['sender'])) { $mailer->Sender = $pMessage['sender']; } $mailer->Host = $gBitSystem->getConfig('bitmailer_servers', $gBitSystem->getConfig('kernel_server_name', '127.0.0.1')); $mailer->Mailer = $gBitSystem->getConfig('bitmailer_protocol', 'smtp'); // Alternative to IsSMTP() $mailer->CharSet = 'UTF-8'; if ($gBitSystem->getConfig('bitmailer_ssl') == 'y') { $mailer->SMTPSecurity = "ssl"; // secure transfer enabled $mailer->Port = $gBitSystem->getConfig('bitmailer_port', '25'); } if ($gBitSystem->getConfig('bitmailer_smtp_username')) { $mailer->SMTPAuth = TRUE; $mailer->Username = $gBitSystem->getConfig('bitmailer_smtp_username'); } if ($gBitSystem->getConfig('bitmailer_smtp_password')) { $mailer->Password = $gBitSystem->getConfig('bitmailer_smtp_password'); } $mailer->WordWrap = $gBitSystem->getConfig('bitmailer_word_wrap', 75); if (!$mailer->SetLanguage($gBitLanguage->getLanguage(), UTIL_PKG_PATH . 'phpmailer/language/')) { $mailer->SetLanguage('en'); } if (!empty($pMessage['x_headers']) && is_array($pMessage['x_headers'])) { foreach ($pMessage['x_headers'] as $name => $value) { /* Not sure what this is intended to do but nothing seems to use it yet but boards that I am hacking on now. 29-11-08 XOXO - Nick if( !$mailer->set( $name, $value ) ) { $mailer->$name = $value; bit_error_log( $mailer->ErrorInfo ); } */ $mailer->AddCustomHeader($name . ":" . $value); } } $mailer->ClearReplyTos(); $mailer->AddReplyTo(!empty($pMessage['replyto']) ? $pMessage['replyto'] : $gBitSystem->getConfig('bitmailer_replyto_email', $gBitSystem->getConfig('bitmailer_sender_email'))); if (empty($pMessage['subject'])) { $mailer->Subject = $gBitSystem->getConfig('site_title', '') . (empty($pMessage['package']) ? '' : " : " . $pMessage['package']) . (empty($pMessage['type']) ? '' : " : " . $pMessage['type']); } else { $mailer->Subject = $pMessage['subject']; } if (!empty($pMessage['message'])) { $mailer->Body = $pMessage['message']; $mailer->IsHTML(TRUE); if (!empty($pMessage['alt_message'])) { $mailer->AltBody = $pMessage['alt_message']; } else { $mailer->AltBody = ''; } } elseif (!empty($pMessage['alt_message'])) { // although plain text, use Body so that clients reading html by default see the msg. header is correctly set as text/plain $mailer->Body = $pMessage['alt_message']; $mailer->IsHTML(FALSE); } return $mailer; }
/** * Sends an HTML email using the phpmailer class (and multipart/alternative to downgrade gracefully) * Sender name and email can be specified, if not specified * name and email of the platform admin are used * * @author Bert Vanderkimpen ICT&O UGent * @author Yannick Warnier <*****@*****.**> * * @param string name of recipient * @param string email of recipient * @param string email subject * @param string email body * @param string sender name * @param string sender e-mail * @param array extra headers in form $headers = array($name => $value) to allow parsing * @param array data file (path and filename) * @param array data to attach a file (optional) * @param bool True for attaching a embedded file inside content html (optional) * @return returns true if mail was sent * @see class.phpmailer.php */ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $senderName = '', $senderEmail = '', $extra_headers = array(), $data_file = array(), $embedded_image = false, $additionalParameters = array()) { // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultName; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail; $link = isset($additionalParameters['link']) ? $additionalParameters['link'] : ''; $swiftMessage = \Swift_Message::newInstance()->setSubject($subject)->setFrom($senderEmail, $senderName)->setTo($recipient_email, $recipient_name)->setBody(Container::getTemplating()->render('ChamiloCoreBundle:default/mail:mail.html.twig', array('content' => $message, 'link' => $link)), 'text/html'); if (!empty($additionalParameters)) { $plugin = new AppPlugin(); $smsPlugin = $plugin->getSMSPluginLibrary(); if ($smsPlugin) { $smsPlugin->send($additionalParameters); } } Container::getMailer()->send($swiftMessage); return 1; global $platform_email; $mail = new PHPMailer(); $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; $mail->CharSet = $platform_email['SMTP_CHARSET']; // Stay far below SMTP protocol 980 chars limit. $mail->WordWrap = 200; if ($platform_email['SMTP_AUTH']) { $mail->SMTPAuth = 1; $mail->Username = $platform_email['SMTP_USER']; $mail->Password = $platform_email['SMTP_PASS']; } // 5 = low, 1 = high $mail->Priority = 3; $mail->SMTPKeepAlive = true; // Default values $notification = new Notification(); $defaultEmail = $notification->getDefaultPlatformSenderEmail(); $defaultName = $notification->getDefaultPlatformSenderName(); // Error to admin. $mail->AddCustomHeader('Errors-To: ' . $defaultEmail); // If the parameter is set don't use the admin. $senderName = !empty($senderName) ? $senderName : $defaultName; $senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail; // Reply to first if (isset($extra_headers['reply_to'])) { $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); $mail->Sender = $extra_headers['reply_to']['mail']; unset($extra_headers['reply_to']); } //If the SMTP configuration only accept one sender if ($platform_email['SMTP_UNIQUE_SENDER']) { $senderName = $platform_email['SMTP_FROM_NAME']; $senderEmail = $platform_email['SMTP_FROM_EMAIL']; } $mail->SetFrom($senderEmail, $senderName); $mail->Subject = $subject; $mail->AltBody = strip_tags(str_replace('<br />', "\n", api_html_entity_decode($message))); // Send embedded image. if ($embedded_image) { // Get all images html inside content. preg_match_all("/<img\\s+.*?src=[\"\\']?([^\"\\' >]*)[\"\\']?[^>]*>/i", $message, $m); // Prepare new tag images. $new_images_html = array(); $i = 1; if (!empty($m[1])) { foreach ($m[1] as $image_path) { $real_path = realpath($image_path); $filename = basename($image_path); $image_cid = $filename . '_' . $i; $encoding = 'base64'; $image_type = mime_content_type($real_path); $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); $new_images_html[] = '<img src="cid:' . $image_cid . '" />'; $i++; } } // Replace origin image for new embedded image html. $x = 0; if (!empty($m[0])) { foreach ($m[0] as $orig_img) { $message = str_replace($orig_img, $new_images_html[$x], $message); $x++; } } } $message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message); $mailView = new Template(null, false, false, false, false, false, false); $mailView->assign('content', $message); $link = $additionalParameters['link']; $mailView->assign('link', $link); $layout = $mailView->get_template('mail/mail.tpl'); $mail->Body = $mailView->fetch($layout); // Attachment ... if (!empty($data_file)) { $mail->AddAttachment($data_file['path'], $data_file['filename']); } // Only valid addresses are accepted. if (is_array($recipient_email)) { foreach ($recipient_email as $dest) { if (api_valid_email($dest)) { $mail->AddAddress($dest, $recipient_name); } } } else { if (api_valid_email($recipient_email)) { $mail->AddAddress($recipient_email, $recipient_name); } else { return 0; } } if (is_array($extra_headers) && count($extra_headers) > 0) { foreach ($extra_headers as $key => $value) { switch (strtolower($key)) { case 'encoding': case 'content-transfer-encoding': $mail->Encoding = $value; break; case 'charset': $mail->Charset = $value; break; case 'contenttype': case 'content-type': $mail->ContentType = $value; break; default: $mail->AddCustomHeader($key . ':' . $value); break; } } } else { if (!empty($extra_headers)) { $mail->AddCustomHeader($extra_headers); } } // WordWrap the html body (phpMailer only fixes AltBody) FS#2988 $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap); // Send the mail message. if (!$mail->Send()) { error_log('ERROR: mail not sent to ' . $recipient_name . ' (' . $recipient_email . ') because of ' . $mail->ErrorInfo . '<br />'); return 0; } if (!empty($additionalParameters)) { $plugin = new AppPlugin(); $smsPlugin = $plugin->getSMSPluginLibrary(); if ($smsPlugin) { $smsPlugin->send($additionalParameters); } } // Clear all the addresses. $mail->ClearAddresses(); return 1; }
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; }
function _SendSMTP() { $config =& $this->config['smtp']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet = 'utf-8'; $mail->Host = $config['host']; $mail->Port = $config['port']; $mail->SMTPSecure = $config['secure']; $mail->SMTPAuth = $config['auth']; $mail->Username = $config['user']; $mail->Password = $config['password']; $mail->Subject = $this->subject; $mail->MsgHTML($this->message); $to = preg_split("/[;\\s,]+/", $this->to, -1, PREG_SPLIT_NO_EMPTY); foreach ($to as $adr) { $mail->AddAddress($adr); } // reply-to MUST be set before from, or else the phpmailer adds the // from address to the reply-to header, which is not what we want for FB // see also PHPMailer::SetFrom($address, $name = '',$auto=1), around line 507 if (!empty($this->replyto)) { if (is_array($this->replyto)) { foreach ($this->replyto as $adr) { $mail->AddReplyTo($adr); } } else { $mail->AddReplyTo($this->replyto); } } if (!empty($this->from)) { // accept formats name@domain.ext or Name <*****@*****.**> $pos = strpos($this->from, '<'); if ($pos === false) { //global $myPage; //$name = $myPage->getConfigS('shopname'); //if( $name ) $mail->SetFrom( $this->from, $name ); //else $mail->SetFrom( $this->from ); $mail->SetFrom($this->from); } else { $name = substr($this->from, 0, $pos); $addr = str_replace('>', '', substr($this->from, $pos + 1)); $mail->SetFrom($addr, $name); } } if (!empty($this->cc)) { if (is_string($this->cc)) { $this->cc = preg_split("/[;\\s,]+/", $this->cc, -1, PREG_SPLIT_NO_EMPTY); } if (is_array($this->cc)) { foreach ($this->cc as $adr) { $mail->AddCC($adr); } } } if (!empty($this->bcc)) { if (is_array($this->bcc)) { foreach ($this->bcc as $adr) { $mail->AddBCC($adr); } } else { $mail->AddBCC($this->bcc); } } if ($this->extra_header) { $mail->AddCustomHeader($this->extra_header); } if ($this->files !== false) { foreach ($this->files as $name => $path) { if (!$mail->AddAttachment($path, $name)) { writeErrorLog('Mailer could locate attachment:', $path); } } } if (!$mail->Send()) { writeErrorLog($mail->ErrorInfo); $this->error = $mail->ErrorInfo; 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|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, 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; }
/** * Always use this function for all emails to users * * @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email * @param object $userfrom user object to send email from. If null, email will come from mahara * @param string $subject email subject * @param string $messagetext text version of email * @param string $messagehtml html version of email (will send both html and text) * @param array $customheaders email headers * @throws EmailException * @throws EmailDisabledException */ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml = '', $customheaders = null) { global $IDPJUMPURL; static $mnetjumps = array(); if (!get_config('sendemail')) { // You can entirely disable Mahara from sending any e-mail via the // 'sendemail' configuration variable return true; } if (empty($userto)) { throw new InvalidArgumentException("empty user given to email_user"); } if (isset($userto->id) && empty($userto->ignoredisabled)) { $maildisabled = property_exists($userto, 'maildisabled') ? $userto->maildisabled : get_account_preference($userto->id, 'maildisabled') == 1; if ($maildisabled) { throw new EmailDisabledException("email for this user has been disabled"); } } // If the user is a remote xmlrpc user, trawl through the email text for URLs // to our wwwroot and modify the url to direct the user's browser to login at // their home site before hitting the link on this site if (!empty($userto->mnethostwwwroot) && !empty($userto->mnethostapp)) { require_once get_config('docroot') . 'auth/xmlrpc/lib.php'; // Form the request url to hit the idp's jump.php if (isset($mnetjumps[$userto->mnethostwwwroot])) { $IDPJUMPURL = $mnetjumps[$userto->mnethostwwwroot]; } else { $mnetjumps[$userto->mnethostwwwroot] = $IDPJUMPURL = PluginAuthXmlrpc::get_jump_url_prefix($userto->mnethostwwwroot, $userto->mnethostapp); } $wwwroot = get_config('wwwroot'); $messagetext = preg_replace_callback('%(' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))%', 'localurl_to_jumpurl', $messagetext); $messagehtml = preg_replace_callback('%href=["\'`](' . $wwwroot . '([\\w_:\\?=#&@/;.~-]*))["\'`]%', 'localurl_to_jumpurl', $messagehtml); } require_once 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer(true); $mail->CharSet = 'UTF-8'; $smtphosts = get_config('smtphosts'); if ($smtphosts == 'qmail') { // use Qmail system $mail->IsQmail(); } else { if (empty($smtphosts)) { // use PHP mail() = sendmail $mail->IsMail(); } else { $mail->IsSMTP(); // use SMTP directly $mail->Host = get_config('smtphosts'); if (get_config('smtpuser')) { // Use SMTP authentication $mail->SMTPAuth = true; $mail->Username = get_config('smtpuser'); $mail->Password = get_config('smtppass'); $mail->SMTPSecure = get_config('smtpsecure'); $mail->Port = get_config('smtpport'); if (get_config('smtpsecure') && !get_config('smtpport')) { // Encrypted connection with no port. Use default one. if (get_config('smtpsecure') == 'ssl') { $mail->Port = 465; } elseif (get_config('smtpsecure') == 'tls') { $mail->Port = 587; } } } } } if (get_config('bounces_handle') && !empty($userto->id) && empty($maildisabled)) { $mail->Sender = generate_email_processing_address($userto->id, $userto); } if (empty($userfrom) || $userfrom->email == get_config('noreplyaddress')) { if (empty($mail->Sender)) { $mail->Sender = get_config('noreplyaddress'); } $mail->From = get_config('noreplyaddress'); $mail->FromName = isset($userfrom->id) ? display_name($userfrom, $userto) : get_config('sitename'); $customheaders[] = 'Precedence: Bulk'; // Try to avoid pesky out of office responses $messagetext .= "\n\n" . get_string('pleasedonotreplytothismessage') . "\n"; if ($messagehtml) { $messagehtml .= "\n\n<p>" . get_string('pleasedonotreplytothismessage') . "</p>\n"; } } else { if (empty($mail->Sender)) { $mail->Sender = $userfrom->email; } $mail->From = $userfrom->email; $mail->FromName = display_name($userfrom, $userto); } $replytoset = false; if (!empty($customheaders) && is_array($customheaders)) { foreach ($customheaders as $customheader) { // To prevent duplicated declaration of the field "Message-ID", // don't add it into the $mail->CustomHeader[]. if (false === stripos($customheader, 'message-id')) { // Hack the fields "In-Reply-To" and "References": // add touser<userID> if (0 === stripos($customheader, 'in-reply-to') || 0 === stripos($customheader, 'references')) { $customheader = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $customheader); } $mail->AddCustomHeader($customheader); } else { list($h, $msgid) = explode(':', $customheader, 2); // Hack the "Message-ID": add touser<userID> to make sure // the "Message-ID" is unique $msgid = preg_replace('/<forumpost(\\d+)/', '<forumpost${1}touser' . $userto->id, $msgid); $mail->MessageID = trim($msgid); } if (0 === stripos($customheader, 'reply-to')) { $replytoset = true; } } } $mail->Subject = substr(stripslashes($subject), 0, 900); try { if ($to = get_config('sendallemailto')) { // Admins can configure the system to send all email to a given address // instead of whoever would receive it, useful for debugging. $usertoname = display_name($userto, $userto, true) . ' (' . get_string('divertingemailto', 'mahara', $to) . ')'; $mail->addAddress($to); $notice = get_string('debugemail', 'mahara', display_name($userto, $userto), $userto->email); $messagetext = $notice . "\n\n" . $messagetext; if ($messagehtml) { $messagehtml = '<p>' . hsc($notice) . '</p>' . $messagehtml; } } else { $usertoname = display_name($userto, $userto); $mail->AddAddress($userto->email, $usertoname); $to = $userto->email; } if (!$replytoset) { $mail->AddReplyTo($mail->From, $mail->FromName); } } catch (phpmailerException $e) { // If there's a phpmailer error already, assume it's an invalid address throw new InvalidEmailException("Cannot send email to {$usertoname} with subject {$subject}. Error from phpmailer was: " . $mail->ErrorInfo); } $mail->WordWrap = 79; if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = $messagetext; } else { $mail->IsHTML(false); $mail->Body = $messagetext; } try { $sent = $mail->Send(); } catch (phpmailerException $e) { $sent = false; } if ($sent) { if ($logfile = get_config('emaillog')) { $docroot = get_config('docroot'); @($client = (string) $_SERVER['REMOTE_ADDR']); @($script = (string) $_SERVER['SCRIPT_FILENAME']); if (strpos($script, $docroot) === 0) { $script = substr($script, strlen($docroot)); } $line = "{$to} <- {$mail->From} - " . str_shorten_text($mail->Subject, 200); @error_log('[' . date("Y-m-d h:i:s") . "] [{$client}] [{$script}] {$line}\n", 3, $logfile); } if (get_config('bounces_handle')) { // Update the count of sent mail update_send_count($userto); } return true; } throw new EmailException("Couldn't send email to {$usertoname} with subject {$subject}. " . "Error from phpmailer was: " . $mail->ErrorInfo); }
$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 $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; } } } do_action_ref_array('phpmailer_init', array(&$phpmailer));
/** * Add a custom header to the outgoing email. * @param string $Name * @param string $Value * @since 2.1 */ public function AddHeader($Name, $Value) { $this->PhpMailer->AddCustomHeader("{$Name}:{$Value}"); }
function emailSWIP($swip) { require_once "../class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->SetLanguage("en", "../"); $mail->Host = EMAILSERVER; // SMTP server $mail->From = REGADMINEMAIL; $mail->FromName = "IP Plan"; $mail->AddAddress(REGEMAIL); $mail->IsHTML(false); $mail->Subject = "SWIP"; $mail->Body = $swip; $mail->AddReplyTo(REGADMINEMAIL); $mail->AddCustomHeader("X-Mailer: PHP/" . phpversion()); //$mail->AddCustomHeader("IPplan version goes here"); if (REGISTRY == "RIPE") { $mail->AddCustomHeader("X-NCC-regid: " . REGID); } if (!@$mail->Send()) { return $mail->ErrorInfo; } /* $header="From: ".REGADMINEMAIL."\n". "Reply-To: ".REGADMINEMAIL."\n". "X-Mailer: PHP/" . phpversion(); if(REGISTRY=="RIPE") { $header.="\nX-NCC-regid: ".REGID."\n"; } mail(REGEMAIL, "SWIP", $swip, $header); */ }
// sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "******"; // GMAIL username $mail->Password = "******"; // GMAIL password $mail->From = "*****@*****.**"; $mail->FromName = "Roomista.com"; $mail->Subject = "Your reservation is completed through roomista.com"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($header); $mail->AddCustomHeader($header2); $mail->AddAddress('*****@*****.**', 'manoj'); // $mail->AddAddress($client_email, $client_name); //$mail->AddCC('*****@*****.**'); //$mail->AddCC('*****@*****.**'); //$mail->AddAddress("*****@*****.**"); $mail->IsHTML(true); // send as HTML if (!$mail->Send()) { echo "Mailer Error: --- " . $mail->ErrorInfo; } else { //If Payment Successed; delete session details of pre paid voucher //UNSET RESERVATION SESSION FIELDS unset($_SESSION['check_in_date']); unset($_SESSION['check_out_date']); unset($_SESSION['no_of_dates']);
/** * 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. * * @param string $body Body text of the email in plain text or HTML * @param mixed $subject Email subject * @param mixed $to Array with several email addresses or single string with one email address * @param mixed $from * @param mixed $sitename * @param mixed $ishtml * @param mixed $bouncemail * @param mixed $attachment * @return bool If successful returns true */ function SendEmailMessage($body, $subject, $to, $from, $sitename, $ishtml = false, $bouncemail = null, $attachments = null, $customheaders = "") { global $maildebug, $maildebugbody; $emailmethod = Yii::app()->getConfig('emailmethod'); $emailsmtphost = Yii::app()->getConfig("emailsmtphost"); $emailsmtpuser = Yii::app()->getConfig("emailsmtpuser"); $emailsmtppassword = Yii::app()->getConfig("emailsmtppassword"); $emailsmtpdebug = Yii::app()->getConfig("emailsmtpdebug"); $emailsmtpssl = Yii::app()->getConfig("emailsmtpssl"); $defaultlang = Yii::app()->getConfig("defaultlang"); $emailcharset = Yii::app()->getConfig("emailcharset"); if ($emailcharset != 'utf-8') { $body = mb_convert_encoding($body, $emailcharset, 'utf-8'); $subject = mb_convert_encoding($subject, $emailcharset, 'utf-8'); $sitename = mb_convert_encoding($sitename, $emailcharset, 'utf-8'); } if (!is_array($to)) { $to = array($to); } if (!is_array($customheaders) && $customheaders == '') { $customheaders = array(); } if (Yii::app()->getConfig('demoMode')) { $maildebug = gT('Email was not sent because demo-mode is activated.'); $maildebugbody = ''; return false; } if (is_null($bouncemail)) { $sender = $from; } else { $sender = $bouncemail; } require_once APPPATH . '/third_party/phpmailer/class.phpmailer.php'; $mail = new PHPMailer(); if (!$mail->SetLanguage($defaultlang, APPPATH . '/third_party/phpmailer/language/')) { $mail->SetLanguage('en', APPPATH . '/third_party/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 = $emailsmtpdebug; } 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 foreach ($to 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); if (strpos($body, "<html>") === false) { $body = "<html>" . $body . "</html>"; } $mail->msgHTML($body, App()->getConfig("publicdir")); // This allow embedded image if we remove the servername from image } else { $mail->IsHTML(false); $mail->Body = $body; } // Add attachments if they are there. if (is_array($attachments)) { foreach ($attachments as $attachment) { // Attachment is either an array with filename and attachment name. if (is_array($attachment)) { $mail->AddAttachment($attachment[0], $attachment[1]); } else { // Or a string with the filename. $mail->AddAttachment($attachment); } } } $mail->Subject = $subject; if ($emailsmtpdebug > 0) { ob_start(); } $sent = $mail->Send(); $maildebug = $mail->ErrorInfo; if ($emailsmtpdebug > 0) { $maildebug .= '<li>' . gT('SMTP debug output:') . '</li><pre>' . strip_tags(ob_get_contents()) . '</pre>'; ob_end_clean(); } $maildebugbody = $mail->Body; //if(!$sent) var_dump($maildebug); return $sent; }
/** * 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; } }
$sender = mb_encode_mimeheader($sender, 'UTF-8', 'Q'); $mail->SetFrom($cf['email']['address'], $sender); // Minor changes every 5 months // Patch changes every 2 weeks // Sub patch first number, changes every ~4 hours // If sub patch is 3 numbers long, its last changes every ~2 minutes // If sub patch is 4 numbers long, its last changes every ~10 seconds $now = strval(time()); $ver = '0.' . substr($now, 2, 1) . '.' . substr($now, 3, 1) . '.' . substr($now, 4, 3); $mail->Version = $ver; $mail->AddAddress($toMail, $toName); $mail->AddBCC($cf['email']['address'], $mail->FromName); $mail->WordWrap = 50; $mail->AddAttachment('./img/favicon64x64.png'); $mail->IsHTML(false); $signature = "\n\n-------------------\nRENSHUU.PAAZMAYA.COM\nhttp://renshuu.paazmaya.com/\nv" . $ver; mb_internal_encoding('UTF-8'); $mail->AddCustomHeader('X-Tonttu-UTF8: ' . mb_encode_mimeheader($cf['title'], 'UTF-8', 'Q')); mb_internal_encoding('UTF-7'); $mail->AddCustomHeader('X-Tonttu-UTF7: ' . mb_encode_mimeheader($cf['title'], 'UTF-7', 'Q')); mb_internal_encoding('ISO-8859-15'); $mail->AddCustomHeader('X-Tonttu-ISO-8859-15: ' . mb_encode_mimeheader($cf['title'], 'ISO-8859-15', 'Q')); mb_internal_encoding('ISO-8859-1'); $mail->AddCustomHeader('X-Tonttu-ISO-8859-1: ' . mb_encode_mimeheader($cf['title'], 'ISO-8859-1', 'Q')); //$mail->AddCustomHeader('Content-Type: text/plain; charset="iso-8859-1"'); $mail->AddCustomHeader('Content-Language: en_GB'); mb_internal_encoding('UTF-8'); $mail->Subject = $subject; $mail->Body = $message . $signature; $mail->Send(); echo "\n" . $mail->ErrorInfo;