/** * Send an email. * * All emails sent by Geeklog are sent through this function. * * NOTE: Please note that using CC: will expose the email addresses of * all recipients. Use with care. * * @param string $to recipients name and email address * @param string $subject subject of the email * @param string $message the text of the email * @param string $from (optional) sender of the the email * @param boolean $html (optional) true if to be sent as HTML email * @param int $priority (optional) add X-Priority header, if > 0 * @param mixed $optional (optional) other headers or CC: * @return boolean true if successful, otherwise false * */ function COM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0, $optional = null) { global $_CONF; static $mailobj; if (empty($from)) { $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['site_mail']); } $to = substr($to, 0, strcspn($to, "\r\n")); if ($optional != null && !is_array($optional)) { $optional = substr($optional, 0, strcspn($optional, "\r\n")); } $from = substr($from, 0, strcspn($from, "\r\n")); $subject = substr($subject, 0, strcspn($subject, "\r\n")); $subject = COM_emailEscape($subject); if (function_exists('CUSTOM_mail')) { return CUSTOM_mail($to, $subject, $message, $from, $html, $priority, $optional); } include_once 'Mail.php'; include_once 'Mail/RFC822.php'; $method = $_CONF['mail_settings']['backend']; if (!isset($mailobj)) { if ($method == 'sendmail' || $method == 'smtp') { $mailobj =& Mail::factory($method, $_CONF['mail_settings']); } else { $method = 'mail'; $mailobj =& Mail::factory($method); } } $charset = COM_getCharset(); $headers = array(); $headers['From'] = $from; if ($method != 'mail') { $headers['To'] = $to; } if ($optional != null && !is_array($optional) && !empty($optional)) { // assume old (optional) CC: header $headers['Cc'] = $optional; } $headers['Date'] = date('r'); // RFC822 formatted date if ($method == 'smtp') { list($usec, $sec) = explode(' ', microtime()); $m = substr($usec, 2, 5); $headers['Message-Id'] = '<' . date('YmdHis') . '.' . $m . '@' . $_CONF['mail_settings']['host'] . '>'; } if ($html) { $headers['Content-Type'] = 'text/html; charset=' . $charset; $headers['Content-Transfer-Encoding'] = '8bit'; } else { $headers['Content-Type'] = 'text/plain; charset=' . $charset; } $headers['Subject'] = $subject; if ($priority > 0) { $headers['X-Priority'] = $priority; } $headers['X-Mailer'] = 'Geeklog ' . VERSION; if (!empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) { $url = COM_getCurrentURL(); if (substr($url, 0, strlen($_CONF['site_admin_url'])) != $_CONF['site_admin_url']) { $headers['X-Originating-IP'] = $_SERVER['REMOTE_ADDR']; } } // add optional headers last if ($optional != null && is_array($optional)) { foreach ($optional as $h => $v) { $headers[$h] = $v; } } $retval = $mailobj->send($to, $headers, $message); if ($retval !== true) { COM_errorLog($retval->toString(), 1); } return $retval === true ? true : false; }
/** * Send an email. * * All emails sent by glFusion are sent through this function now. * * @param string $to recipients name and email address * @param string $subject subject of the email * @param string $message the text of the email * @param string $from (optional) sender of the the email * @param boolean $html (optional) true if to be sent as HTML email * @param int $priority (optional) add X-Priority header, if > 0 * @param string $cc (optional) other recipients (name + email) * @param string $altBody (optional) alternative message body (plain text) * @return boolean true if successful, otherwise false * * @note Please note that using the $cc parameter will expose the email addresses * of all recipients. Use with care. * */ function COM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0, $cc = '', $altBody = '') { global $_CONF; $subject = substr($subject, 0, strcspn($subject, "\r\n")); $subject = COM_emailEscape($subject); if (function_exists('CUSTOM_mail')) { return CUSTOM_mail($to, $subject, $message, $from, $html, $priority, $cc); } require_once $_CONF['path'] . 'lib/phpmailer/class.phpmailer.php'; $mail = new PHPMailer(); $mail->SetLanguage('en', $_CONF['path'] . 'lib/phpmailer/language/'); $mail->CharSet = COM_getCharset(); $mail->XMailer = 'glFusion CMS v' . GVERSION . ' (http://www.glfusion.org)'; if ($_CONF['mail_backend'] == 'smtp') { $mail->IsSMTP(); $mail->Host = $_CONF['mail_smtp_host']; $mail->Port = $_CONF['mail_smtp_port']; if ($_CONF['mail_smtp_secure'] != 'none') { $mail->SMTPSecure = $_CONF['mail_smtp_secure']; } if ($_CONF['mail_smtp_auth']) { $mail->SMTPAuth = true; $mail->Username = $_CONF['mail_smtp_username']; $mail->Password = $_CONF['mail_smtp_password']; } $mail->Mailer = "smtp"; } elseif ($_CONF['mail_backend'] == 'sendmail') { $mail->Mailer = "sendmail"; $mail->Sendmail = $_CONF['mail_sendmail_path']; } else { $mail->Mailer = "mail"; } $mail->WordWrap = 76; $mail->IsHTML($html); if ($html) { $mail->Body = COM_filterHTML($message); } else { $mail->Body = $message; } if ($altBody != '') { $mail->AltBody = $altBody; } $mail->Subject = $subject; if (is_array($from) && isset($from[0]) && $from[0] != '') { if ($_CONF['use_from_site_mail'] == 1) { $mail->From = $_CONF['site_mail']; $mail->AddReplyTo($from[0]); } else { $mail->From = $from[0]; } } else { $mail->From = $_CONF['site_mail']; } if (is_array($from) && isset($from[1]) && $from[1] != '') { $mail->FromName = $from[1]; } else { $mail->FromName = $_CONF['site_name']; } if (is_array($to) && isset($to[0]) && $to[0] != '') { if (isset($to[1]) && $to[1] != '') { $mail->AddAddress($to[0], $to[1]); } else { $mail->AddAddress($to[0]); } } else { // assume old style.... $mail->AddAddress($to); } if (isset($cc[0]) && $cc[0] != '') { if (isset($cc[1]) && $cc[1] != '') { $mail->AddCC($cc[0], $cc[1]); } else { $mail->AddCC($cc[0]); } } else { // assume old style.... if (isset($cc) && $cc != '') { $mail->AddCC($cc); } } if ($priority) { $mail->Priority = 1; } if (!$mail->Send()) { COM_errorLog("Email Error: " . $mail->ErrorInfo); return false; } return true; }