コード例 #1
0
ファイル: email_api.php プロジェクト: tamtrong/testlink
function email_send($p_from, $p_recipient, $p_subject, $p_message, $p_cc = '', $p_exit_on_error = false, $htmlFormat = false)
{
    global $g_phpMailer_smtp;
    $op = new stdClass();
    $op->status_ok = true;
    $op->msg = 'ok';
    // Check fatal Error
    $smtp_host = config_get('smtp_host');
    if (is_blank($smtp_host)) {
        $op->status_ok = false;
        $op->msg = lang_get('stmp_host_unconfigured');
        return $op;
    }
    $t_recipient = trim($p_recipient);
    $t_subject = string_email(trim($p_subject));
    $t_message = string_email_links(trim($p_message));
    # short-circuit if no recipient is defined, or email disabled
    # note that this may cause signup messages not to be sent
    # Visit http://phpmailer.sourceforge.net
    # if you have problems with phpMailer
    $mail = new PHPMailer();
    $mail->PluginDir = PHPMAILER_PATH;
    // 20090201 - franciscom
    // Need to get strings file for php mailer
    // To avoid problems I choose ENglish
    $mail->SetLanguage('en', PHPMAILER_PATH . 'language' . DIRECTORY_SEPARATOR);
    # Select the method to send mail
    switch (config_get('phpMailer_method')) {
        case 0:
            $mail->IsMail();
            break;
        case 1:
            $mail->IsSendmail();
            break;
        case 2:
            $mail->IsSMTP();
            # SMTP collection is always kept alive
            #
            $mail->SMTPKeepAlive = true;
            # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
            # but there is no common method to reset PHPMailer object, so
            # I see the smallest evel - to initialize only one 'private'
            # field phpMailer::smtp in order to reuse smtp connection.
            if (is_null($g_phpMailer_smtp)) {
                register_shutdown_function('email_smtp_close');
            } else {
                $mail->smtp = $g_phpMailer_smtp;
            }
            break;
    }
    $mail->IsHTML($htmlFormat);
    # set email format to plain text
    $mail->WordWrap = 80;
    $mail->Priority = config_get('mail_priority');
    # Urgent = 1, Not Urgent = 5, Disable = 0
    $mail->CharSet = config_get('charset');
    $mail->Host = config_get('smtp_host');
    $mail->From = config_get('from_email');
    if (!is_blank($p_from)) {
        $mail->From = $p_from;
    }
    $mail->Sender = config_get('return_path_email');
    $mail->FromName = '';
    if (!is_blank(config_get('smtp_username'))) {
        # Use SMTP Authentication
        $mail->SMTPAuth = true;
        $mail->Username = config_get('smtp_username');
        $mail->Password = config_get('smtp_password');
    }
    $t_debug_to = '';
    # add to the Recipient list
    $t_recipient_list = split(',', $t_recipient);
    while (list(, $t_recipient) = each($t_recipient_list)) {
        if (!is_blank($t_recipient)) {
            $mail->AddAddress($t_recipient, '');
        }
    }
    // 20051106 - fm
    $t_cc_list = split(',', $p_cc);
    while (list(, $t_cc) = each($t_cc_list)) {
        if (!is_blank($t_cc)) {
            $mail->AddCC($t_cc, '');
        }
    }
    $mail->Subject = $t_subject;
    $mail->Body = make_lf_crlf("\n" . $t_message);
    if (!$mail->Send()) {
        if ($p_exit_on_error) {
            print "PROBLEMS SENDING MAIL TO: {$p_recipient}<br />";
            print 'Mailer Error: ' . $mail->ErrorInfo . '<br />';
            exit;
        } else {
            $op->status_ok = false;
            $op->msg = $mail->ErrorInfo;
            return $op;
        }
    }
    if (!is_null($mail->smtp)) {
        # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
        # but there is no common method to reset PHPMailer object, so
        # I see the smallest evel - to initialize only one 'private'
        # field phpMailer::smtp in order to reuse smtp connection.
        $g_phpMailer_smtp = $mail->smtp;
    }
    return $op;
}
コード例 #2
0
/**  
 * Prepare a string for plain text display in email and add URLs for bug
 * links and cvs links
 */
function string_email_links($p_string)
{
    $p_string = string_email($p_string);
    return $p_string;
}
コード例 #3
0
/**
 * This function sends an email message based on the supplied email data.
 *
 * @param EmailData $p_email_data
 * @return bool
 */
function email_send($p_email_data)
{
    global $g_phpMailer;
    $t_email_data = $p_email_data;
    $t_recipient = trim($t_email_data->email);
    $t_subject = string_email(trim($t_email_data->subject));
    $t_message = string_email_links(trim($t_email_data->body));
    $t_debug_email = config_get('debug_email');
    $t_mailer_method = config_get('phpMailer_method');
    $t_log_msg = 'ERROR: Message could not be sent - ';
    if (is_null($g_phpMailer)) {
        if ($t_mailer_method == PHPMAILER_METHOD_SMTP) {
            register_shutdown_function('email_smtp_close');
        }
        $mail = new PHPMailer(true);
    } else {
        $mail = $g_phpMailer;
    }
    if (isset($t_email_data->metadata['hostname'])) {
        $mail->Hostname = $t_email_data->metadata['hostname'];
    }
    # @@@ should this be the current language (for the recipient) or the default one (for the user running the command) (thraxisp)
    $t_lang = config_get('default_language');
    if ('auto' == $t_lang) {
        $t_lang = config_get('fallback_language');
    }
    $mail->SetLanguage(lang_get('phpmailer_language', $t_lang));
    # Select the method to send mail
    switch (config_get('phpMailer_method')) {
        case PHPMAILER_METHOD_MAIL:
            $mail->IsMail();
            break;
        case PHPMAILER_METHOD_SENDMAIL:
            $mail->IsSendmail();
            break;
        case PHPMAILER_METHOD_SMTP:
            $mail->IsSMTP();
            // SMTP collection is always kept alive
            $mail->SMTPKeepAlive = true;
            if (!is_blank(config_get('smtp_username'))) {
                # Use SMTP Authentication
                $mail->SMTPAuth = true;
                $mail->Username = config_get('smtp_username');
                $mail->Password = config_get('smtp_password');
            }
            if (!is_blank(config_get('smtp_connection_mode'))) {
                $mail->SMTPSecure = config_get('smtp_connection_mode');
            }
            $mail->Port = config_get('smtp_port');
            break;
    }
    $mail->IsHTML(false);
    # set email format to plain text
    $mail->WordWrap = 80;
    # set word wrap to 50 characters
    $mail->Priority = $t_email_data->metadata['priority'];
    # Urgent = 1, Not Urgent = 5, Disable = 0
    $mail->CharSet = $t_email_data->metadata['charset'];
    $mail->Host = config_get('smtp_host');
    $mail->From = config_get('from_email');
    $mail->Sender = config_get('return_path_email');
    $mail->FromName = config_get('from_name');
    $mail->AddCustomHeader('Auto-Submitted:auto-generated');
    $mail->AddCustomHeader('X-Auto-Response-Suppress: All');
    if (OFF !== $t_debug_email) {
        $t_message = 'To: ' . $t_recipient . "\n\n" . $t_message;
        $t_recipient = $t_debug_email;
    }
    try {
        $mail->AddAddress($t_recipient, '');
    } catch (phpmailerException $e) {
        log_event(LOG_EMAIL, $t_log_msg . $mail->ErrorInfo);
        $t_success = false;
        $mail->ClearAllRecipients();
        $mail->ClearAttachments();
        $mail->ClearReplyTos();
        $mail->ClearCustomHeaders();
        return $t_success;
    }
    $mail->Subject = $t_subject;
    $mail->Body = make_lf_crlf("\n" . $t_message);
    if (isset($t_email_data->metadata['headers']) && is_array($t_email_data->metadata['headers'])) {
        foreach ($t_email_data->metadata['headers'] as $t_key => $t_value) {
            switch ($t_key) {
                case 'Message-ID':
                    /* Note: hostname can never be blank here as we set metadata['hostname']
                       in email_store() where mail gets queued. */
                    if (!strchr($t_value, '@') && !is_blank($mail->Hostname)) {
                        $t_value = $t_value . '@' . $mail->Hostname;
                    }
                    $mail->set('MessageID', "<{$t_value}>");
                    break;
                case 'In-Reply-To':
                    $mail->AddCustomHeader("{$t_key}: <{$t_value}@{$mail->Hostname}>");
                    break;
                default:
                    $mail->AddCustomHeader("{$t_key}: {$t_value}");
                    break;
            }
        }
    }
    try {
        $t_success = $mail->Send();
        if ($t_success) {
            $t_success = true;
            if ($t_email_data->email_id > 0) {
                email_queue_delete($t_email_data->email_id);
            }
        } else {
            # We should never get here, as an exception is thrown after failures
            log_event(LOG_EMAIL, $t_log_msg . $mail->ErrorInfo);
            $t_success = false;
        }
    } catch (phpmailerException $e) {
        log_event(LOG_EMAIL, $t_log_msg . $mail->ErrorInfo);
        $t_success = false;
    }
    $mail->ClearAllRecipients();
    $mail->ClearAttachments();
    $mail->ClearReplyTos();
    $mail->ClearCustomHeaders();
    return $t_success;
}
コード例 #4
0
/** 
 * sends the actual email 
 * 
 * @param boolean $p_exit_on_error == true - calls exit() on errors, else - returns true 
 * 		on success and false on errors
 * @param boolean $htmlFormat specify text type true = html, false (default) = plain text
 */
function email_send($p_from, $p_recipient, $p_subject, $p_message, $p_cc = '', $p_exit_on_error = false, $htmlFormat = false, $opt = null)
{
    global $g_phpMailer;
    $op = new stdClass();
    $op->status_ok = true;
    $op->msg = 'ok';
    $options = array('strip_email_links' => true);
    $options = array_merge($options, (array) $opt);
    // Check fatal Error
    $smtp_host = config_get('smtp_host');
    if (is_blank($smtp_host)) {
        $op->status_ok = false;
        $op->msg = lang_get('stmp_host_unconfigured');
        return $op;
        // >>>---->
    }
    $t_recipient = trim($p_recipient);
    $t_subject = string_email(trim($p_subject));
    $t_message = trim($p_message);
    $t_message = $options['strip_email_links'] ? string_email_links($p_message) : $p_message;
    # short-circuit if no recipient is defined, or email disabled
    # note that this may cause signup messages not to be sent
    # Visit http://phpmailer.sourceforge.net
    # if you have problems with phpMailer
    $mail = new PHPMailer();
    $mail->PluginDir = PHPMAILER_PATH;
    // Need to get strings file for php mailer
    // To avoid problems I choose ENglish
    $mail->SetLanguage('en', PHPMAILER_PATH . 'language' . DIRECTORY_SEPARATOR);
    # Select the method to send mail
    switch (config_get('phpMailer_method')) {
        case PHPMAILER_METHOD_MAIL:
            $mail->IsMail();
            break;
        case PHPMAILER_METHOD_SENDMAIL:
            $mail->IsSendmail();
            break;
        case PHPMAILER_METHOD_SMTP:
            $mail->IsSMTP();
            # SMTP collection is always kept alive
            $mail->SMTPKeepAlive = true;
            # Copied from last mantis version
            if (!is_blank(config_get('smtp_username'))) {
                # Use SMTP Authentication
                $mail->SMTPAuth = true;
                $mail->Username = config_get('smtp_username');
                $mail->Password = config_get('smtp_password');
            }
            if (!is_blank(config_get('smtp_connection_mode'))) {
                $mail->SMTPSecure = config_get('smtp_connection_mode');
            }
            $mail->Port = config_get('smtp_port');
            // is not a lot clear why this is useful (franciscom)
            // need to use sometime to understand .
            if (is_null($g_phpMailer)) {
                register_shutdown_function('email_smtp_close');
            } else {
                $mail = $g_phpMailer;
            }
            break;
    }
    $mail->IsHTML($htmlFormat);
    # set email format to plain text
    $mail->WordWrap = 80;
    $mail->Priority = config_get('mail_priority');
    # Urgent = 1, Not Urgent = 5, Disable = 0
    $mail->CharSet = config_get('charset');
    $mail->Host = config_get('smtp_host');
    $mail->From = config_get('from_email');
    if (!is_blank($p_from)) {
        $mail->From = $p_from;
    }
    $mail->Sender = config_get('return_path_email');
    $mail->FromName = '';
    $t_debug_to = '';
    # add to the Recipient list
    $t_recipient_list = explode(',', $t_recipient);
    while (list(, $t_recipient) = each($t_recipient_list)) {
        if (!is_blank($t_recipient)) {
            $mail->AddAddress($t_recipient, '');
        }
    }
    $t_cc_list = explode(',', $p_cc);
    while (list(, $t_cc) = each($t_cc_list)) {
        if (!is_blank($t_cc)) {
            $mail->AddCC($t_cc, '');
        }
    }
    $mail->Subject = $t_subject;
    $mail->Body = make_lf_crlf("\n" . $t_message);
    if (!$mail->Send()) {
        if ($p_exit_on_error) {
            print "PROBLEMS SENDING MAIL TO: {$p_recipient}<br />";
            print 'Mailer Error: ' . $mail->ErrorInfo . '<br />';
            exit;
        } else {
            $op->status_ok = false;
            $op->msg = $mail->ErrorInfo;
            return $op;
        }
    }
    return $op;
}
コード例 #5
0
function email_send($p_email_data)
{
    global $g_phpMailer_smtp;
    $t_email_data = $p_email_data;
    $t_recipient = trim($t_email_data->email);
    $t_subject = string_email(trim($t_email_data->subject));
    $t_message = string_email_links(trim($t_email_data->body));
    $t_debug_email = config_get('debug_email');
    # Visit http://phpmailer.sourceforge.net
    # if you have problems with phpMailer
    $mail = new PHPMailer();
    $mail->PluginDir = PHPMAILER_PATH;
    if (isset($t_email_data->metadata['hostname'])) {
        $mail->Hostname = $t_email_data->metadata['hostname'];
    }
    # @@@ should this be the current language (for the recipient) or the default one (for the user running the command) (thraxisp)
    $t_lang = config_get('default_language');
    if ('auto' == $t_lang) {
        $t_lang = config_get('fallback_language');
    }
    $mail->SetLanguage(lang_get('phpmailer_language', $t_lang), PHPMAILER_PATH . 'language' . DIRECTORY_SEPARATOR);
    # Select the method to send mail
    switch (config_get('phpMailer_method')) {
        case 0:
            $mail->IsMail();
            break;
        case 1:
            $mail->IsSendmail();
            break;
        case 2:
            $mail->IsSMTP();
            # SMTP collection is always kept alive
            #
            $mail->SMTPKeepAlive = true;
            # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
            # but there is no common method to reset PHPMailer object, so
            # I see the smallest evel - to initialize only one 'private'
            # field phpMailer::smtp in order to reuse smtp connection.
            if (is_null($g_phpMailer_smtp)) {
                register_shutdown_function('email_smtp_close');
            } else {
                $mail->smtp = $g_phpMailer_smtp;
            }
            break;
    }
    $mail->IsHTML(false);
    # set email format to plain text
    $mail->WordWrap = 80;
    # set word wrap to 50 characters
    $mail->Priority = $t_email_data->metadata['priority'];
    # Urgent = 1, Not Urgent = 5, Disable = 0
    $mail->CharSet = $t_email_data->metadata['charset'];
    $mail->Host = config_get('smtp_host');
    $mail->From = config_get('from_email');
    $mail->Sender = escapeshellcmd(config_get('return_path_email'));
    $mail->FromName = config_get('from_name');
    if (!is_blank(config_get('smtp_username'))) {
        # Use SMTP Authentication
        $mail->SMTPAuth = true;
        $mail->Username = config_get('smtp_username');
        $mail->Password = config_get('smtp_password');
    }
    if (OFF !== $t_debug_email) {
        $t_message = 'To: ' . $t_recipient . "\n\n" . $t_message;
        $mail->AddAddress($t_debug_email, '');
    } else {
        $mail->AddAddress($t_recipient, '');
    }
    $mail->Subject = $t_subject;
    $mail->Body = make_lf_crlf("\n" . $t_message);
    if (isset($t_email_data->metadata['headers']) && is_array($t_email_data->metadata['headers'])) {
        foreach ($t_email_data->metadata['headers'] as $t_key => $t_value) {
            $mail->AddCustomHeader("{$t_key}: {$t_value}");
        }
    }
    if (!$mail->Send()) {
        $t_success = false;
    } else {
        $t_success = true;
        if ($t_email_data->email_id > 0) {
            email_queue_delete($t_email_data->email_id);
        }
    }
    if (!is_null($mail->smtp)) {
        # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
        # but there is no common method to reset PHPMailer object, so
        # I see the smallest evel - to initialize only one 'private'
        # field phpMailer::smtp in order to reuse smtp connection.
        $g_phpMailer_smtp = $mail->smtp;
    }
    return $t_success;
}
コード例 #6
0
function string_email_links($p_string)
{
    $p_string = string_email($p_string);
    $p_string = string_process_bug_link($p_string, false);
    $p_string = string_process_bugnote_link($p_string, false);
    $p_string = string_process_cvs_link($p_string, false);
    return $p_string;
}
コード例 #7
0
ファイル: upload.php プロジェクト: jhron/mantis-releasemgt
 $t_emails = explode(',', plugin_config_get('notify_email', PLUGINS_RELEASEMGT_NOTIFY_EMAIL_DEFAULT));
 foreach ($t_emails as $t_email) {
     if (trim($t_email) != '') {
         $t_id_list[] = trim($t_email);
     }
 }
 $t_email_ids = array_unique($t_id_list);
 if (defined('MANTIS_VERSION')) {
     $t_mantis_version = MANTIS_VERSION;
 } else {
     $t_mantis_version = config_get('mantis_version');
 }
 if (version_compare($t_mantis_version, '1.1.0a2', '>=')) {
     foreach ($t_email_ids as $t_email) {
         $t_recipient = trim($t_email);
         $t_subject = string_email(trim($t_subject));
         $t_message = string_email_links(trim($t_message));
         $t_email_data = new EmailData();
         $t_email_data->email = $t_recipient;
         $t_email_data->subject = $t_subject;
         $t_email_data->body = $t_message;
         $t_email_data->metadata = array();
         $t_email_data->metadata['headers'] = array('X-Mantis' => 'ReleaseMgt');
         $t_email_data->metadata['priority'] = config_get('mail_priority');
         $t_email_data->metadata['charset'] = 'utf-8';
         $t_email_data->metadata['plugins_htmlmail_html_message'] = base64_encode($t_html_message);
         email_queue_add($t_email_data);
     }
     if (OFF == config_get('email_send_using_cronjob')) {
         email_send_all();
     }
コード例 #8
0
ファイル: email_api.php プロジェクト: centaurustech/BenFund
function email_send($p_recipient, $p_subject, $p_message, $p_header = '', $p_category = '', $p_exit_on_error = true)
{
    global $g_phpMailer_smtp;
    $t_recipient = trim($p_recipient);
    $t_subject = string_email(trim($p_subject));
    $t_message = string_email_links(trim($p_message));
    # short-circuit if no recipient is defined, or email disabled
    # note that this may cause signup messages not to be sent
    if (is_blank($p_recipient) || OFF == config_get('enable_email_notification')) {
        return;
    }
    # for debugging only
    #PRINT $t_recipient.'<br />'.$t_subject.'<br />'.$t_message.'<br />'.$t_headers;
    #exit;
    #PRINT '<br />xxxRecipient ='.$t_recipient.'<br />';
    #PRINT 'Headers ='.nl2br($t_headers).'<br />';
    #PRINT $t_subject.'<br />';
    #PRINT nl2br($t_message).'<br />';
    #exit;
    $t_debug_email = config_get('debug_email');
    # Visit http://phpmailer.sourceforge.net
    # if you have problems with phpMailer
    $mail = new PHPMailer();
    $mail->PluginDir = PHPMAILER_PATH;
    # @@@ should this be the current language (for the recipient) or the default one (for the user running the command) (thraxisp)
    $mail->SetLanguage(lang_get('phpmailer_language', lang_get_current()), PHPMAILER_PATH . 'language' . DIRECTORY_SEPARATOR);
    # Select the method to send mail
    switch (config_get('phpMailer_method')) {
        case 0:
            $mail->IsMail();
            break;
        case 1:
            $mail->IsSendmail();
            break;
        case 2:
            $mail->IsSMTP();
            # SMTP collection is always kept alive
            #
            $mail->SMTPKeepAlive = true;
            # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
            # but there is no common method to reset PHPMailer object, so
            # I see the smallest evel - to initialize only one 'private'
            # field phpMailer::smtp in order to reuse smtp connection.
            if (is_null($g_phpMailer_smtp)) {
                register_shutdown_function('email_smtp_close');
            } else {
                $mail->smtp = $g_phpMailer_smtp;
            }
            break;
    }
    $mail->IsHTML(false);
    # set email format to plain text
    $mail->WordWrap = 80;
    # set word wrap to 50 characters
    $mail->Priority = config_get('mail_priority');
    # Urgent = 1, Not Urgent = 5, Disable = 0
    $mail->CharSet = lang_get('charset', lang_get_current());
    $mail->Host = config_get('smtp_host');
    $mail->From = config_get('from_email');
    $mail->Sender = config_get('return_path_email');
    $mail->FromName = '';
    if (!is_blank(config_get('smtp_username'))) {
        # Use SMTP Authentication
        $mail->SMTPAuth = true;
        $mail->Username = config_get('smtp_username');
        $mail->Password = config_get('smtp_password');
    }
    $t_debug_to = '';
    # add to the Recipient list
    $t_recipient_list = split(',', $t_recipient);
    while (list(, $t_recipient) = each($t_recipient_list)) {
        if (!is_blank($t_recipient)) {
            if (OFF === $t_debug_email) {
                $mail->AddAddress($t_recipient, '');
            } else {
                $t_debug_to .= !is_blank($t_debug_to) ? ', ' : '';
                $t_debug_to .= $t_recipient;
            }
        }
    }
    # add to the BCC list
    $t_debug_bcc = '';
    $t_bcc_list = split(',', $p_header);
    while (list(, $t_bcc) = each($t_bcc_list)) {
        if (!is_blank($t_bcc)) {
            if (OFF === $t_debug_email) {
                $mail->AddBCC($t_bcc, '');
            } else {
                $t_debug_bcc .= !is_blank($t_debug_bcc) ? ', ' : '';
                $t_debug_bcc .= $t_bcc;
            }
        }
    }
    if (OFF !== $t_debug_email) {
        $t_message = "\n" . $t_message;
        if (!is_blank($t_debug_bcc)) {
            $t_message = 'Bcc: ' . $t_debug_bcc . "\n" . $t_message;
        }
        if (!is_blank($t_debug_to)) {
            $t_message = 'To: ' . $t_debug_to . "\n" . $t_message;
        }
        $mail->AddAddress($t_debug_email, '');
    }
    $mail->Subject = $t_subject;
    $mail->Body = make_lf_crlf("\n" . $t_message);
    if (EMAIL_CATEGORY_PROJECT_CATEGORY == config_get('email_set_category')) {
        $mail->AddCustomHeader("Keywords: {$p_category}");
    }
    if (!$mail->Send()) {
        print "PROBLEMS SENDING MAIL TO: {$p_recipient}<br />";
        print 'Mailer Error: ' . $mail->ErrorInfo . '<br />';
        if ($p_exit_on_error) {
            exit;
        } else {
            return false;
        }
    }
    if (!is_null($mail->smtp)) {
        # @@@ yarick123: It is said in phpMailer comments, that phpMailer::smtp has private access.
        # but there is no common method to reset PHPMailer object, so
        # I see the smallest evel - to initialize only one 'private'
        # field phpMailer::smtp in order to reuse smtp connection.
        $g_phpMailer_smtp = $mail->smtp;
    }
    return true;
}