Ejemplo n.º 1
0
<?php

$msg_status = array(0 => "Deleted", 1 => "Unread", 3 => "Read", 4 => "Trashed");
switch ($action) {
    case 0:
        // Preview Mail
        check_admin_authorization();
        $body = new Template("templates/mail/mail.tmpl.php");
        $mail = get_mail_headers();
        if ($mail) {
            $body->set("mail", $mail);
            foreach ($mail as $key => $value) {
                $body->set($key, $value);
            }
        }
        break;
    case 1:
        // View Message
        check_admin_authorization();
        $breadcrumbs .= " >> View Message";
        $message = view_message();
        $body = new Template("templates/mail/mail.view.tmpl.php");
        $body->set("msg_status", $msg_status);
        $body->set("message", $message);
        break;
    case 2:
        // Modify Message
        check_admin_authorization();
        $breadcrumbs .= " >> Edit Message";
        $message = view_message();
        $javascript = new Template("templates/mail/js.tmpl.php");
Ejemplo n.º 2
0
function libxml_error_handler($errno, $errstr, $errfile, $errline)
{
    global $config;
    $message = "Sorry, this subject\\'s data has been corrupted.";
    $ir = $config->IssueReport;
    //Prepare an e-mail message
    $email = "Issue Report:\n\n" . "Date:    " . date('Y-m-d') . "\n" . "User:    "******"\n" . "File:    " . $errfile . ":" . $errline . "\n" . "Message: " . $errstr . "\n" . "\n" . "POST:\n" . "--------------------------------------\n" . print_r($_POST, true) . "\n" . "--------------------------------------\n";
    //Send e-mail
    $result = mail($ir['to'], $ir['subject'], $email, get_mail_headers($config));
    if ($result) {
        $message .= "<br><br>This issue has been reported to " . $ir['to'] . ".<br>You will receive an e-mail when the issue is fixed.";
    } else {
        $message .= "<br><br>Also, we were unable automatically notify " . $ir['to'] . " of this issue." . "<br>Please send an e-mail to <a href='mailto:" . $ir['to'] . "'>" . $ir['to'] . "</a>" . " with screenshots and other relevant information.";
    }
    ajax_error($message);
}
Ejemplo n.º 3
0
/**
 * Sends an email, wrapping PHP's mail() function.
 * ALL emails sent by b2evolution must be sent through this function (for consistency and for logging)
 *
 * {@link $current_locale} will be used to set the charset.
 *
 * Note: we use a single \n as line ending, though it does not comply to {@link http://www.faqs.org/rfcs/rfc2822 RFC2822}, but seems to be safer,
 * because some mail transfer agents replace \n by \r\n automatically.
 *
 * @todo Unit testing with "nice addresses" This gets broken over and over again.
 *
 * @param string Recipient email address.
 * @param string Recipient name.
 * @param string Subject of the mail
 * @param string|array The message text OR Array: 'charset', 'full', 'html', 'text'
 * @param string From address, being added to headers (we'll prevent injections); see {@link http://securephp.damonkohler.com/index.php/Email_Injection}.
 *               Defaults to {@link GeneralSettings::get('notification_sender_email') } if NULL.
 * @param string From name.
 * @param array Additional headers ( headername => value ). Take care of injection!
 * @param integer User ID
 * @return boolean True if mail could be sent (not necessarily delivered!), false if not - (return value of {@link mail()})
 */
function send_mail($to, $to_name, $subject, $message, $from = NULL, $from_name = NULL, $headers = array(), $user_ID = NULL)
{
    global $servertimenow;
    // Stop a request from the blocked IP addresses or Domains
    antispam_block_request();
    global $debug, $app_name, $app_version, $current_locale, $current_charset, $evo_charset, $locales, $Debuglog, $Settings, $demo_mode, $sendmail_additional_params;
    $message_data = $message;
    if (is_array($message_data) && isset($message_data['full'])) {
        // If content is multipart
        $message = $message_data['full'];
    } elseif (is_string($message_data)) {
        // Convert $message_data to array
        $message_data = array('full' => $message);
    }
    // Replace secret content in the mail logs message body
    $message = preg_replace('~\\$secret_content_start\\$.*\\$secret_content_end\\$~', '***secret-content-removed***', $message);
    // Remove secret content marks from the message
    $message_data = str_replace(array('$secret_content_start$', '$secret_content_end$'), '', $message_data);
    // Memorize email address
    $to_email_address = $to;
    $NL = "\r\n";
    if ($demo_mode) {
        // Debug mode restriction: Sending email in debug mode is not allowed
        return false;
    }
    if (!is_array($headers)) {
        // Make sure $headers is an array
        $headers = array($headers);
    }
    if (empty($from)) {
        $from = user_get_notification_sender($user_ID, 'email');
    }
    if (empty($from_name)) {
        $from_name = user_get_notification_sender($user_ID, 'name');
    }
    // Pass these data for SMTP mailer
    $message_data['to_email'] = $to;
    $message_data['to_name'] = empty($to_name) ? NULL : $to_name;
    $message_data['from_email'] = $from;
    $message_data['from_name'] = empty($from_name) ? NULL : $from_name;
    $return_path = $Settings->get('notification_return_path');
    // Add real name into $from...
    if (!is_windows()) {
        // fplanque: Windows XP, Apache 1.3, PHP 4.4, MS SMTP : will not accept "nice" addresses.
        if (!empty($to_name)) {
            $to = '"' . mail_encode_header_string($to_name) . '" <' . $to . '>';
        }
        if (!empty($from_name)) {
            $from = '"' . mail_encode_header_string($from_name) . '" <' . $from . '>';
        }
    }
    $from = mail_sanitize_header_string($from, true);
    // From has to go into headers
    $headers['From'] = $from;
    if (!empty($return_path)) {
        // Set a return path
        $headers['Return-Path'] = $return_path;
    }
    // echo 'sending email to: ['.htmlspecialchars($to).'] from ['.htmlspecialchars($from).']';
    $clear_subject = $subject;
    $subject = mail_encode_header_string($subject);
    $message = str_replace(array("\r\n", "\r"), $NL, $message);
    // Convert encoding of message (from internal encoding to the one of the message):
    // fp> why do we actually convert to $current_charset?
    // dh> I do not remember. Appears to make sense sending it unconverted in $evo_charset.
    // asimo> converting the message creates wrong output, no need for conversion, however this needs further investigation
    // $message = convert_charset( $message, $current_charset, $evo_charset );
    if (!isset($headers['Content-Type'])) {
        // Specify charset and content-type of email
        $headers['Content-Type'] = 'text/plain; charset=' . $current_charset;
    }
    $headers['MIME-Version'] = '1.0';
    $headers['Date'] = gmdate('r', $servertimenow);
    // ADDITIONAL HEADERS:
    $headers['X-Mailer'] = $app_name . ' ' . $app_version . ' - PHP/' . phpversion();
    $ip_list = implode(',', get_ip_list());
    if (!empty($ip_list)) {
        // Add X-Remote_Addr param only if its value is not empty
        $headers['X-Remote-Addr'] = $ip_list;
    }
    // COMPACT HEADERS:
    $headerstring = get_mail_headers($headers, $NL);
    // Set an additional parameter for the return path:
    if (!empty($sendmail_additional_params)) {
        $additional_parameters = str_replace(array('$from-address$', '$return-address$'), array($from, empty($return_path) ? $from : $return_path), $sendmail_additional_params);
    } else {
        $additional_parameters = '';
    }
    if (mail_is_blocked($to_email_address)) {
        // Check if the email address is blocked
        $Debuglog->add('Sending mail to &laquo;' . htmlspecialchars($to_email_address) . '&raquo; FAILED, because this email marked with spam or permanent errors.', 'error');
        mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'blocked');
        return false;
    }
    // SEND MESSAGE:
    if ($debug > 1) {
        // We agree to die for debugging...
        if (!evo_mail($to, $subject, $message_data, $headers, $additional_parameters)) {
            mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'error');
            debug_die('Sending mail from &laquo;' . htmlspecialchars($from) . '&raquo; to &laquo;' . htmlspecialchars($to) . '&raquo;, Subject &laquo;' . htmlspecialchars($subject) . '&raquo; FAILED.');
        }
    } else {
        // Soft debugging only....
        if (!evo_mail($to, $subject, $message_data, $headers, $additional_parameters)) {
            $Debuglog->add('Sending mail from &laquo;' . htmlspecialchars($from) . '&raquo; to &laquo;' . htmlspecialchars($to) . '&raquo;, Subject &laquo;' . htmlspecialchars($subject) . '&raquo; FAILED.', 'error');
            mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'error');
            return false;
        }
    }
    $Debuglog->add('Sent mail from &laquo;' . htmlspecialchars($from) . '&raquo; to &laquo;' . htmlspecialchars($to) . '&raquo;, Subject &laquo;' . htmlspecialchars($subject) . '&raquo;.');
    mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'ok');
    return true;
}
Ejemplo n.º 4
0
$email = strtolower(trim($_POST['email']));
try {
    $config = new \NRG\Configuration(CONFIG_FILE);
    $dbconf = $config->Database;
    //Make sure the username is registered with this application
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    $user = $db->searchUser($email);
    if (!empty($user)) {
        if ($user['requested'] == 1) {
            ajax_error('Your access request is pending approval.');
        }
        if ($user['roleID']) {
            ajax_error('Your username has been enabled, please log in.');
        } else {
            ajax_error('Your access request is currently being reviewed.');
        }
    }
    //Looks like there is nothing else left to do, except add the user to the Acl table with
    //NULL privileges
    $db->createUser($email);
    $ur = $config->UserRegistration;
    //Prepare an e-mail message
    $message = "User {$email} requested access to " . $_SERVER['HTTP_HOST'] . " from " . $_SERVER['REMOTE_ADDR'] . ".";
    //Send e-mail
    $result = mail($ur['to'], $ur['subject'], $message, get_mail_headers($config));
    //Send the result back to the server
    ajax_result(array("success" => 1, "mail" => $result));
} catch (Exception $e) {
    error_log($e->getMessage(), 0);
    ajax_error("Internal server error. Please try again later");
}
Ejemplo n.º 5
0
/**
 * Send mail by SMTP Swift Mailer
 *
 * @param string Receiver, or receivers of the mail
 * @param string Subject of the email
 * @param string|array Message OR Array: 'charset', 'full', 'html', 'text'
 * @param array Email headers
 * @param string Additional flags as command line options
 * @return boolean TRUE on success
 */
function evo_mail_smtp($to, $subject, $message, $headers = array(), $additional_parameters = '')
{
    $headers_string = get_mail_headers($headers);
    // Check if we can use SMTP Swift Mailer
    if (check_smtp_mailer() === true && ($Swift_Mailer =& get_Swift_Mailer())) {
        // Use Swift Mailer to send emails using SMTP
        // Get charset from content type part
        $charset = isset($headers['Content-Type']) && preg_match('#charset=(.+)$#i', $headers['Content-Type'], $charset) ? $charset[1] : NULL;
        // Create a Swift_Message object
        $Swift_Message = Swift_Message::newInstance();
        // Subject:
        $Swift_Message->setSubject($subject);
        // To:
        if (empty($message['to_email'])) {
            // Use only email address
            $Swift_Message->setTo($to);
        } else {
            // Use address with name
            $Swift_Message->setTo($message['to_email'], $message['to_name']);
        }
        // Body:
        if (isset($headers['Content-Type']) && preg_match('#^[^;]+#i', $headers['Content-Type'], $content_type)) {
            switch ($content_type[0]) {
                case 'multipart/mixed':
                    // MULTIPLE:
                    if (is_array($message)) {
                        // Body is multiple
                        $Swift_Message->setBody($message['html'], 'multipart/alternative', $message['charset']);
                        $Swift_Message->addPart($message['html'], 'text/html', $message['charset']);
                        $Swift_Message->addPart($message['text'], 'text/plain', $message['charset']);
                        break;
                    } else {
                        // Unknown case, Send email with text/plain format
                        $content_type[0] = 'text/plain';
                    }
                case 'text/html':
                    // HTML:
                // HTML:
                case 'text/plain':
                    // TEXT:
                    $Swift_Message->setBody($message, $content_type, $charset);
                    break;
                default:
                    // Unknown content type
                    $Swift_Message->setBody($message, null, $charset);
                    break;
            }
        } else {
            // Unknown content type
            $Swift_Message->setBody($message, null, $charset);
        }
        // From:
        if (!empty($message['from_email'])) {
            // Use address with name
            $Swift_Message->setFrom($message['from_email'], $message['from_name']);
        } elseif (!empty($headers['From'])) {
            // Use only email address
            $Swift_Message->setFrom($headers['From']);
        }
        if (!empty($headers['Reply-To'])) {
            // Reply-To:
            $Swift_Message->setReplyTo($headers['Reply-To']);
        }
        if (!empty($headers['Return-Path'])) {
            // Return-Path:
            $Swift_Message->setReturnPath($headers['Return-Path']);
        }
        if (!empty($headers['Date'])) {
            // Date:
            $Swift_Message->setDate($headers['Date']);
        }
        // Send the message
        return $Swift_Mailer->send($Swift_Message);
    }
    // No email was sent
    return false;
}