Ejemplo n.º 1
0
function send_email($bcc_list, $subject, $bb_body, $reply_to = NULL, $prefix = NULL, $footer = NULL, $headers = NULL)
{
    global $EMAIL_ADDRESS, $EMAIL_USERNAME, $EMAIL_PASSWORD, $SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL, $LMT_EMAIL;
    require_once PATH::lib() . "/swiftmailer/swift_required.php";
    //Instead of using parameter default values, so we can pass NULL. And it's more readable.
    if (count($bcc_list) == 0) {
        return true;
    }
    if (is_null($reply_to)) {
        $reply_to = array($EMAIL_ADDRESS => 'LHS Math Club Mailbot');
    }
    if (is_null($prefix)) {
        $prefix = '[LHS Math Club]';
    }
    if (is_null($footer)) {
        $footer = "LHS Math Club\n[url]" . get_site_url() . "[/url]\nTo stop receiving LHSMATH emails, contact [email]webmaster@lhsmath.org[/email].";
    }
    if (is_null($headers)) {
        $headers = array();
    }
    if (is_string($bcc_list)) {
        $bcc_list = array($bcc_list);
    }
    if (!is_array($bcc_list) || !is_string($subject) || !is_string($bb_body) || !is_array($reply_to) && !is_string($reply_to) || !is_string($prefix) || !is_string($footer) || !is_array($headers)) {
        return 'Invalid email parameters.';
    }
    if (($error_msg = val_email_msg($subject, $bb_body)) !== true) {
        return $error_msg;
    }
    if ($footer != "") {
        $bb_body .= "\n\n\n---\n{$footer}\n";
    }
    //Attach footer.
    $html = BBCode($bb_body);
    //BBCode it.
    $subject = preg_replace("/[^\\S ]/ui", '', strip_tags($prefix . ' ' . $subject));
    //"remove everything that's not [non-whitespace or space]"
    //preg_replace("/[^[:alnum][:space]]/ui", '', $string);?
    //Ok everything seems to be working, let's go ahead
    Swift_Preferences::getInstance()->setCacheType('array');
    //Prevents a ton of warnings about SwiftMail's DiskKeyCache, thus actually speeding things up considerably.
    //Connect to the SMTP server
    $transport = Swift_SmtpTransport::newInstance($SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL)->setUsername($EMAIL_USERNAME)->setPassword($EMAIL_PASSWORD);
    //Make a Mailer that will send through that transport (limiting to 50/send)
    $mailer = Swift_Mailer::newInstance($transport);
    //$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(50, 1));//Max 50 emails per send, 1 sec delay between sends
    try {
        //Mush all info into the Mailer
        $message = Swift_Message::newInstance($subject)->setFrom(array($EMAIL_ADDRESS => 'LHS Math Club Mailbot'))->setBcc($bcc_list)->setContentType("text/html")->setBody($html)->setReplyTo($reply_to);
        foreach ($headers as $field => $value) {
            //Add custom headers, such as listserv stuff.
            $message->getHeaders()->addTextHeader($field, $value);
        }
        //Send the message
        if (!$mailer->send($message)) {
            LOG::fatal('Error sending email');
        }
    } catch (Exception $e) {
        LOG::fatal('Email exception: ' . $e->getMessage());
    }
    return true;
}
Ejemplo n.º 2
0
require_once '../../../.lib/lmt-functions.php';
restrict_access('A');
if (isset($_POST['lmti_do_preview_message'])) {
    preview_message();
} else {
    if (isset($_POST['lmti_do_post_message'])) {
        if (($error_msg = lmt_send_individuals_email($_POST['subject'], $_POST['body'])) !== true) {
            show_page($error_msg);
        } else {
            alert('Your message has been sent', 1);
            header('Location: Individuals');
            //Reloads the page
        }
    } else {
        if (isset($_POST['lmti_do_reedit_message'])) {
            if (($error_msg = val_email_msg($subject, $body)) !== true) {
                show_page($error_msg);
            } else {
                show_page('');
            }
        } else {
            show_page('');
        }
    }
}
function show_page($err)
{
    // Put the cursor in the first field
    global $body_onload, $use_rel_external_script;
    $body_onload = 'document.forms[\'lmtIndividualComposeMessage\'].subject.focus();externalLinks();';
    $use_rel_external_script = true;