コード例 #1
0
ファイル: dbbackup.class.php プロジェクト: spacequad/glfusion
 /**
  *   Send an email with attachments.
  *   This is a verbatim copy of COM_mail(), but with the $attachments
  *   paramater added and 3 extra lines of code near the end.
  *
  *   @param  string  $to         Receiver's email address
  *   @param  string  $from       Sender's email address
  *   @param  string  $subject    Message Subject
  *   @param  string  $message    Message Body
  *   @param  boolean $html       True for HTML message, False for Text
  *   @param  integer $priority   Message priority value
  *   @param  string  $cc         Other recipients
  *   @param  string  $altBody    Alt. body (text)
  *   @param  array   $attachments    Array of attachments
  *   @return boolean             True on success, False on Failure
  */
 private function SendMail($to, $subject, $message, $from = '', $html = false, $priority = 0, $cc = '', $altBody = '', $attachments = array())
 {
     global $_CONF;
     $subject = substr($subject, 0, strcspn($subject, "\r\n"));
     $subject = COM_emailEscape($subject);
     require_once $_CONF['path'] . 'lib/phpmailer/class.phpmailer.php';
     $mail = new PHPMailer();
     $mail->SetLanguage('en', $_CONF['path'] . 'lib/phpmailer/language/');
     $mail->CharSet = COM_getCharset();
     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;
     }
     // Add attachments
     foreach ($attachments as $key => $value) {
         $mail->AddAttachment($value);
     }
     if (!$mail->Send()) {
         COM_errorLog("Email Error: " . $mail->ErrorInfo);
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: lib-common.php プロジェクト: alxstuart/ajfs.me
/**
* 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;
}
コード例 #3
0
ファイル: lib-common.php プロジェクト: NewRoute/glfusion
function COM_emailNotification($msgData = array())
{
    global $_CONF;
    // define the maximum number of emails allowed per bcc
    $maxEmailsPerSend = 10;
    // ensure we have something to send...
    if (!isset($msgData['htmlmessage']) && !isset($msgData['textmessage'])) {
        COM_errorLog("COM_emailNotification() - No message data provided");
        return false;
        // no message defined
    }
    if (empty($msgData['htmlmessage']) && empty($msgData['textmessage'])) {
        COM_errorLog("COM_emailNotification() - Empty message data provided");
        return false;
        // no text in either...
    }
    if (!isset($msgData['subject']) || empty($msgData['subject'])) {
        COM_errorLog("COM_emailNotification() - No subject provided");
        return false;
        // must have a subject
    }
    $queued = 0;
    $subject = substr($msgData['subject'], 0, strcspn($msgData['subject'], "\r\n"));
    $subject = COM_emailEscape($subject);
    require_once $_CONF['path'] . 'lib/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    $mail->SetLanguage('en', $_CONF['path'] . 'lib/phpmailer/language/');
    $mail->CharSet = COM_getCharset();
    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;
    if (isset($msgData['htmlmessage']) && !empty($msgData['htmlmessage'])) {
        $mail->IsHTML(true);
        $mail->Body = $msgData['htmlmessage'];
        if (isset($msgData['textmessage']) && !empty($msgData['textmessage'])) {
            $mail->AltBody = $msgData['textmessage'];
        }
    } else {
        $mail->IsHTML(false);
        if (isset($msgData['textmessage']) && !empty($msgData['textmessage'])) {
            $mail->Body = $msgData['textmessage'];
        }
    }
    $mail->Subject = $subject;
    if (isset($msgData['embeddedImage']) && is_array($msgData['embeddedImage'])) {
        foreach ($msgData['embeddedImage'] as $embeddedImage) {
            $mail->AddEmbeddedImage($embeddedImage['file'], $embeddedImage['name'], $embeddedImage['filename'], $embeddedImage['encoding'], $embeddedImage['mime']);
        }
    }
    if (is_array($msgData['from'])) {
        $mail->From = $msgData['from']['email'];
        $mail->FromName = $msgData['from']['name'];
    } else {
        $mail->From = $msgData['from'];
        $mail->FromName = $_CONF['site_name'];
    }
    $queued = 0;
    if (is_array($msgData['to'])) {
        foreach ($msgData['to'] as $to) {
            if (is_array($to)) {
                $mail->AddBCC($to['email'], $to['name']);
            } else {
                if (COM_isEmail($to)) {
                    $mail->AddBCC($to);
                }
            }
            $queued++;
            if ($queued >= $maxEmailsPerSend) {
                if (!$mail->Send()) {
                    COM_errorLog("Email Error: " . $mail->ErrorInfo);
                }
                $queued = 0;
                $mail->ClearBCCs();
            }
        }
    }
    if ($queued > 0) {
        if (!@$mail->Send()) {
            COM_errorLog("Email Error: " . $mail->ErrorInfo);
        }
    }
}
コード例 #4
0
ファイル: lib-commonTest.php プロジェクト: mystralkk/geeklog
 public function testEmailEscape()
 {
     // Line 3090
     $email = '*****@*****.**';
     $scenario['CUSTOM_emailEscape'] = function_exists('CUSTOM_emailEscape');
     $scenario['iconv_mime_encode'] = function_exists('iconv_mime_encode');
     $scenario['preg_match'] = preg_match('/[^0-9a-z\\-\\.,:;\\?! ]/i', $email);
     foreach ($scenario as $function => $exists) {
         $escapedEmail = '=?iso-8859-1?B?am9obmRvZUBkb21haW4uY29t?=';
         if ($exists) {
             $this->assertEquals($escapedEmail, COM_emailEscape($email), 'Error tested using ' . $function);
         }
     }
 }
コード例 #5
0
/**
 * Takes a name and an email address and returns a string that vaguely
 * resembles an email address specification conforming to RFC(2)822 ...
 *
 * @param      string $name    name, e.g. John Doe
 * @param      string $address email address only, e.g. john.doe@example.com
 * @return     string          formatted email address
 * @deprecated since v2.1.2
 */
function COM_formatEmailAddress($name, $address)
{
    $name = trim($name);
    $address = trim($address);
    if (function_exists('CUSTOM_formatEmailAddress')) {
        return CUSTOM_formatEmailAddress($name, $address);
    }
    $formatted_name = COM_emailEscape($name);
    // if the name comes back unchanged, it's not UTF-8, so preg_match is fine
    if ($formatted_name == $name && preg_match('/[^0-9a-z ]/i', $name)) {
        $formatted_name = str_replace('"', '\\"', $formatted_name);
        $formatted_name = '"' . $formatted_name . '"';
    }
    return $formatted_name . ' <' . $address . '>';
}