/** ----------------------------- /** Send email /** -----------------------------*/ function send_email() { global $DSP, $DB, $IN, $FNS, $REGX, $LANG, $SESS, $LOC, $PREFS; $debug_msg = ''; /** ----------------------------- /** Are we missing any fields? /** -----------------------------*/ if (!$IN->GBL('from', 'POST') or !$IN->GBL('subject', 'POST') or !$IN->GBL('message', 'POST')) { return $DSP->error_message($LANG->line('empty_form_fields')); } /** ----------------------------- /** Fetch $_POST data /** -----------------------------*/ // We'll turn the $_POST data into variables for simplicity $groups = array(); $list_ids = array(); foreach ($_POST as $key => $val) { if (substr($key, 0, 6) == 'group_') { $groups[] = $val; } elseif (substr($key, 0, 5) == 'list_') { $list_ids[] = $val; } else { ${$key} = stripslashes($val); } } /** ----------------------------- /** Verify privileges /** -----------------------------*/ if (count($groups) > 0 and !$DSP->allowed_group('can_email_member_groups')) { return $DSP->no_access_message($LANG->line('not_allowed_to_email_member_groups')); } if (count($list_ids) > 0 and !$DSP->allowed_group('can_email_mailinglist') and $this->mailinglist_exists == TRUE) { return $DSP->no_access_message($LANG->line('not_allowed_to_email_mailinglist')); } if (count($groups) == 0 and count($list_ids) == 0 and !$IN->GBL('recipient', 'POST')) { return $DSP->error_message($LANG->line('empty_form_fields')); } /** ------------------------------- /** Assign data for caching /** -------------------------------*/ $cache_data = array('cache_id' => '', 'cache_date' => $LOC->now, 'total_sent' => 0, 'from_name' => $name, 'from_email' => $from, 'recipient' => $recipient, 'cc' => $cc, 'bcc' => $bcc, 'recipient_array' => '', 'subject' => $subject, 'message' => $message, 'plaintext_alt' => $plaintext_alt, 'mailtype' => $mailtype, 'text_fmt' => $text_fmt, 'wordwrap' => $wordwrap, 'priority' => $priority); /** --------------------------------------- /** Apply text formatting if necessary /** ---------------------------------------*/ if ($text_fmt != 'none' && $text_fmt != '') { if (!class_exists('Typography')) { require PATH_CORE . 'core.typography' . EXT; } $TYPE = new Typography(0); $TYPE->parse_smileys = FALSE; $subject = $TYPE->filter_censored_words($subject); $message = $TYPE->parse_type($message, array('text_format' => $text_fmt, 'html_format' => 'all', 'auto_links' => 'n', 'allow_img_url' => 'y')); } /** ----------------------------- /** Send a single email /** -----------------------------*/ if (count($groups) == 0 and count($list_ids) == 0) { require PATH_CORE . 'core.email' . EXT; $to = $recipient == '' ? $SESS->userdata['email'] : $recipient; $email = new EEmail(); $email->wordwrap = $wordwrap == 'y' ? TRUE : FALSE; $email->mailtype = $mailtype; $email->priority = $priority; $email->from($from, $name); $email->to($to); $email->cc($cc); $email->bcc($bcc); $email->subject($subject); $email->message($message, $plaintext_alt); $error = FALSE; if (!$email->Send()) { $error = TRUE; } $debug_msg = $this->debug_message($email->debug_msg); if ($error == TRUE) { return $DSP->error_message($LANG->line('error_sending_email') . $debug_msg, 0); } /** --------------------------------- /** Save cache data /** ---------------------------------*/ $cache_data['total_sent'] = $this->fetch_total($to, $cc, $bcc); $this->save_cache_data($cache_data); /** --------------------------------- /** Show success message /** ---------------------------------*/ $DSP->set_return_data($LANG->line('email_sent'), $DSP->qdiv('defaultPad', $DSP->qdiv('success', $LANG->line('email_sent_message'))) . $debug_msg, $LANG->line('email_sent')); // We're done return; } // Send Multi-emails /** ---------------------------------------- /** Is Batch Mode set? /** ----------------------------------------*/ $batch_mode = $PREFS->ini('email_batchmode'); $batch_size = $PREFS->ini('email_batch_size'); if (!is_numeric($batch_size)) { $batch_mode = 'n'; } $emails = array(); /** --------------------------------- /** Fetch member group emails /** ---------------------------------*/ if (count($groups) > 0) { $sql = "SELECT exp_members.member_id, exp_members.email, exp_members.screen_name \n\t\t\t\t\tFROM exp_members, exp_member_groups\n\t\t\t\t\tWHERE exp_members.group_id = exp_member_groups.group_id \n\t\t\t\t\tAND exp_member_groups.site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "' \n\t\t\t\t\tAND include_in_mailinglists = 'y' "; if (isset($_POST['accept_admin_email'])) { $sql .= "AND exp_members.accept_admin_email = 'y' "; } $sql .= "AND exp_member_groups.group_id IN ("; foreach ($groups as $id) { $sql .= "'" . $DB->escape_str($id) . "',"; } $sql = substr($sql, 0, -1); $sql .= ")"; // Run the query $query = $DB->query($sql); if ($query->num_rows > 0) { foreach ($query->result as $row) { $emails['m' . $row['member_id']] = array($row['email'], $row['screen_name']); } } } /** --------------------------------- /** Fetch mailing list emails /** ---------------------------------*/ $list_templates = array(); if ($this->mailinglist_exists == TRUE) { if (count($list_ids) > 0) { $sql = "SELECT authcode, email, list_id FROM exp_mailing_list WHERE list_id IN ("; foreach ($list_ids as $id) { $sql .= "'" . $DB->escape_str($id) . "',"; // Fetch the template for each list $query = $DB->query("SELECT list_template, list_title FROM exp_mailing_lists WHERE list_id = '" . $DB->escape_str($id) . "'"); $list_templates[$id] = array('list_template' => $query->row['list_template'], 'list_title' => $query->row['list_title']); } $sql = substr($sql, 0, -1); $sql .= ")"; $sql .= " ORDER BY user_id"; $query = $DB->query($sql); // No result? Show error message if ($query->num_rows == 0 && sizeof($emails) == 0) { return $DSP->set_return_data($LANG->line('send_an_email'), $DSP->qdiv('defaultPad', $DSP->qdiv('alert', $LANG->line('no_email_matching_criteria'))), $LANG->line('send_an_email')); } if ($query->num_rows > 0) { foreach ($query->result as $row) { $emails['l' . $row['authcode']] = array($row['email'], $row['list_id']); } } } } /** ---------------------------------------- /** Kill duplicates /** ----------------------------------------*/ $cleaned_emails = array(); foreach ($emails as $key => $value) { if (is_array($value)) { $val = $value['0']; } else { $val = $value; } if (!isset($cleaned_emails[$key])) { $cleaned_emails[$key] = $value; } } $emails = $cleaned_emails; /** ---------------------------------------- /** After all that, do we have any emails? /** ----------------------------------------*/ if (count($emails) == 0 and $recipient == '') { return $DSP->set_return_data($LANG->line('send_an_email'), $DSP->qdiv('defaultPad', $DSP->qdiv('alert', $LANG->line('no_email_matching_criteria'))), $LANG->line('send_an_email')); } /** ---------------------------------------- /** Do we have any CCs or BCCs? /** ----------------------------------------*/ // If so, we'll send those separately first $total_sent = 0; $recips = array(); if ($cc != '' || $bcc != '') { if (!class_exists('EEmail')) { require PATH_CORE . 'core.email' . EXT; } $to = $recipient == '' ? $SESS->userdata['email'] : $recipient; $email = new EEmail(); $email->wordwrap = $wordwrap == 'y' ? TRUE : FALSE; $email->mailtype = $mailtype; $email->priority = $priority; $email->from($from, $name); $email->to($to); $email->cc($cc); $email->bcc($bcc); $email->subject($subject); $email->message($message, $plaintext_alt); $error = FALSE; if (!$email->Send()) { $error = TRUE; } $debug_msg = $this->debug_message($email->debug_msg); if ($error == TRUE) { return $DSP->error_message($LANG->line('error_sending_email') . $debug_msg, 0); } $total_sent = $this->fetch_total($to, $cc, $bcc); } else { // No CC/BCCs? Convert recipients to an array so we can include them in the email sending cycle if ($recipient != '') { $recips = $this->convert_recipients($recipient); } } if (count($recips) > 0) { $emails = array_merge($emails, $recips); } // Store email cache $cache_data['recipient_array'] = addslashes(serialize($emails)); $cache_data['total_sent'] = 0; $id = $this->save_cache_data($cache_data, $groups, $list_ids); /** ---------------------------------------- /** If batch-mode is not set, send emails /** ----------------------------------------*/ if (count($emails) <= $batch_size) { $batch_mode = 'n'; } if ($batch_mode == 'n') { $action_id = $FNS->fetch_action_id('Mailinglist', 'unsubscribe'); if (!class_exists('EEmail')) { require PATH_CORE . 'core.email' . EXT; } $email = new EEmail(); $email->wordwrap = $wordwrap == 'y' ? TRUE : FALSE; $email->mailtype = $mailtype; $email->priority = $priority; foreach ($emails as $key => $val) { $screen_name = ''; $list_id = FALSE; if (is_array($val) and substr($key, 0, 1) == 'm') { $screen_name = $val['1']; $val = $val['0']; } elseif (is_array($val) and substr($key, 0, 1) == 'l') { $list_id = $val['1']; $val = $val['0']; } $email->initialize(); $email->to($val); $email->from($from, $name); $email->subject($subject); // We need to add the unsubscribe link to emails - but only ones // from the mailing list. When we gathered the email addresses // above, we added one of three prefixes to the array key: // // m = member id // l = mailing list // r = general recipient // Make a copy so we don't mess up the original $msg = $message; $msg_alt = $plaintext_alt; if (substr($key, 0, 1) == 'l') { $msg = $this->parse_template($list_templates[$list_id], $msg, $action_id, substr($key, 1), $mailtype); $msg_alt = $this->parse_template($list_templates[$list_id], $msg_alt, $action_id, substr($key, 1), 'plain'); } $msg = str_replace('{name}', $screen_name, $msg); $msg_alt = str_replace('{name}', $screen_name, $msg_alt); $email->message($msg, $msg_alt); $error = FALSE; if (!$email->Send()) { $error = TRUE; } $debug_msg = $this->debug_message($email->debug_msg); if ($error == TRUE) { // Let's adjust the recipient array up to this point reset($recipient_array); $recipient_array = addslashes(serialize(array_slice($recipient_array, $i))); $DB->query("UPDATE exp_email_cache SET total_sent = '{$total_sent}', recipient_array = '{$recipient_array}' WHERE cache_id = '" . $DB->escape_str($id) . "'"); return $DSP->error_message($LANG->line('error_sending_email') . $debug_msg, 0); } $total_sent++; } /** ---------------------------------------- /** Update email cache /** ----------------------------------------*/ $DB->query("UPDATE exp_email_cache SET total_sent = '{$total_sent}', recipient_array = '' WHERE cache_id = '" . $DB->escape_str($id) . "'"); /** ---------------------------------------- /** Success Mesage /** ----------------------------------------*/ $DSP->set_return_data($LANG->line('email_sent'), $DSP->qdiv('defaultPad', $DSP->qdiv('success', $LANG->line('email_sent_message'))) . $DSP->qdiv('defaultPad', $DSP->qdiv('', $LANG->line('total_emails_sent') . NBS . NBS . $total_sent)) . $debug_msg, $LANG->line('email_sent')); // We're done return; } /** ---------------------------------------- /** Start Batch-Mode /** ----------------------------------------*/ // Turn on "refresh" // By putting the URL in the $DSP->refresh variable we'll tell the // system to write a <meta> refresh header, starting the batch process $DSP->refresh = BASE . AMP . 'C=communicate' . AMP . 'M=batch_send' . AMP . 'id=' . $id; $DSP->ref_rate = 6; // Kill the bread-crumb links, just to keep it away from the user $DSP->show_crumb = FALSE; // Write the initial message, telling the user the batch processor is about to start $r = $DSP->heading(BR . $LANG->line('sending_email')); $r .= $DSP->qdiv('itemWrapper', $LANG->line('batchmode_ready_to_begin')); $r .= $DSP->qdiv('', $DSP->qdiv('alert', $LANG->line('batchmode_warning'))); $DSP->body = $r; }
// Get the member email address $sql_member = "SELECT email FROM exp_members WHERE member_id='" . $row['member_id'] . "'"; $sql_query = $DB->query($sql_member); // Assemble the email $receipient = $sql_query->row['email']; $bcc_emails = $PREFS->core_ini['webmaster_email']; $email_subject = "Your Be Fabulous subscription has expired"; $email_msg = "Hello\n"; $email_msg = $email_msg . "\n"; $email_msg = $email_msg . "This is just a brief email to let you know that your Be Fabulous 12 month subscription has expired.\n"; $email_msg = $email_msg . "\n"; $email_msg = $email_msg . "To re-subscribe simply visit http://www.be-fabulous.co.uk and log-in to your account. You will see an option on the right hand side of the 'All about you' page to 'Upgrade your subscription'.\n"; $email_msg = $email_msg . "\n"; $email_msg = $email_msg . "If you need any help or have any questions please don't hesitate to contact us by replying to this email or calling Karen on +44 (0) 7970 732057.\n"; $email_msg = $email_msg . "\n"; $email_msg = $email_msg . " - End of Message - \n"; // Send the Email $email = new EEmail(); $email->wordwrap = false; $email->mailtype = 'text'; $email->validate = true; $email->from($PREFS->core_ini['webmaster_email'], $PREFS->core_ini['webmaster_name']); $email->to($receipient); $email->bcc($bcc_emails); $email->subject($email_subject); $email->message($REGX->entities_to_ascii($email_msg)); $email->Send(); $email->initialize(); } } }
function cp_welcome_email_send($member_id) { global $PREFS, $DB, $REGX; if ( ! class_exists('EEmail')) { require PATH_CORE.'core.email'.EXT; } $password_string = "abcdefghijklmnopqrstuvwxyz1234567890"; $password = ""; for($i=0; $i<8; $i++) { $password .= $password_string[ rand(0, strlen($password_string)-1) ]; } $message = $this->settings["welcome_email_body"]; $from = $this->settings["welcome_email_from"]; $subject = $this->settings["welcome_email_subject"]; $subject = str_replace("{site_name}", $PREFS->ini('site_name'), $subject); $query = $DB->query("SELECT username, screen_name, email from exp_members WHERE member_id = " . $member_id); $message = str_replace("{password}", $password, $message); $message = str_replace("{username}", $query->row["username"], $message); $message = str_replace("{name}", $query->row["screen_name"], $message); $message = str_replace("{site_name}", $PREFS->ini('site_name'), $message); $message = str_replace("{site_url}", $PREFS->ini('site_url'), $message); $DB->query("UPDATE exp_members SET password = SHA('". $password . "') WHERE member_id = " . $member_id); $to = $query->row["email"]; $email = new EEmail; $email->wordwrap = false; $email->mailtype = 'text'; $email->from( $from ); $email->to( $to ); if ($this->settings["welcome_email_bcc"]=="yes") { $email->bcc( $PREFS->ini('webmaster_email') ); } $email->subject( $subject ); $email->message($REGX->entities_to_ascii( $message )); $email->Send(); }
/** ---------------------------------- /** Send Member Email /** ----------------------------------*/ function send_email() { global $DB, $IN, $FNS, $OUT, $LANG, $PREFS, $LOC, $SESS; if ( ! $member_id = $IN->GBL('MID', 'POST')) { return false; } /** ---------------------------------------- /** Is the user banned? /** ----------------------------------------*/ if ($SESS->userdata['is_banned'] == TRUE) { return false; } /** --------------------------------- /** Is the user logged in? /** ---------------------------------*/ if ($SESS->userdata('member_id') == 0) { return $this->profile_login_form($this->_member_path('email_console/'.$member_id)); } /** --------------------------------- /** Are we missing data? /** ---------------------------------*/ if ( ! $member_id = $IN->GBL('MID', 'POST')) { return false; } if ( ! isset($_POST['subject']) || ! isset($_POST['message'])) { return false; } if ($_POST['subject'] == '' OR $_POST['message'] == '') { return $OUT->show_user_error('submission', array($LANG->line('mbr_missing_fields'))); } /** ---------------------------------------- /** Check Email Timelock /** ----------------------------------------*/ if ($SESS->userdata['group_id'] != 1) { $lock = $PREFS->ini('email_console_timelock'); if (is_numeric($lock) AND $lock != 0) { if (($SESS->userdata['last_email_date'] + ($lock*60)) > $LOC->now) { return $this->_var_swap($this->_load_element('email_user_message'), array( 'lang:message' => str_replace("%x", $lock, $LANG->line('mbr_email_timelock_not_expired')), 'css_class' => 'highlight', 'lang:close_window' => $LANG->line('mbr_close_window') ) ); } } } /** --------------------------------- /** Do we have a secure hash? /** ---------------------------------*/ if ($PREFS->ini('secure_forms') == 'y') { $query = $DB->query("SELECT COUNT(*) AS count FROM exp_security_hashes WHERE hash='".$DB->escape_str($_POST['XID'])."' AND ip_address = '".$IN->IP."' AND date > UNIX_TIMESTAMP()-7200"); if ($query->row['count'] == 0) { return false; } $DB->query("DELETE FROM exp_security_hashes WHERE (hash='".$DB->escape_str($_POST['XID'])."' AND ip_address = '".$IN->IP."') OR date < UNIX_TIMESTAMP()-7200"); } /** --------------------------------- /** Does the recipient accept email? /** ---------------------------------*/ $query = $DB->query("SELECT email, screen_name, accept_user_email FROM exp_members WHERE member_id = '{$member_id}'"); if ($query->num_rows == 0) { return false; } if ($query->row['accept_user_email'] != 'y') { return $this->_var_swap($this->_load_element('email_user_message'), array( 'lang:message' => $LANG->line('mbr_email_not_accepted'), 'css_class' => 'highlight' ) ); } $message = stripslashes($_POST['message'])."\n\n"; $message .= $LANG->line('mbr_email_forwarding')."\n"; $message .= $PREFS->ini('site_url')."\n"; $message .= $LANG->line('mbr_email_forwarding_cont'); /** ---------------------------- /** Send email /** ----------------------------*/ if ( ! class_exists('EEmail')) { require PATH_CORE.'core.email'.EXT; } $email = new EEmail; $email->wordwrap = true; $email->from($SESS->userdata['email']); $email->subject(stripslashes($_POST['subject'])); $email->message($message); if (isset($_POST['self_copy'])) { /* If CC'ing the send, they get the email and the recipient is BCC'ed Because Rick says his filter blocks emails without a To: field */ $email->to($SESS->userdata['email']); $email->bcc($query->row['email']); } else { $email->to($query->row['email']); } $swap['lang:close_window'] = $LANG->line('mbr_close_window'); if ( ! $email->Send()) { $swap['lang:message'] = $LANG->line('mbr_email_error'); $swap['css_class'] = 'alert'; } else { $this->log_email($query->row['email'], $query->row['screen_name'], $_POST['subject'], $_POST['message']); $swap['lang:message'] = $LANG->line('mbr_good_email'); $swap['css_class'] = 'success'; $DB->query("UPDATE exp_members SET last_email_date = '{$LOC->now}' WHERE member_id = '".$SESS->userdata('member_id')."'"); } $this->_set_page_title($LANG->line('email_console')); return $this->_var_swap($this->_load_element('email_user_message'), $swap); }