This is it below:
=============
<?php
/***************************************************************************
* admin_mass_email.php
* -------------------
* begin : Thu jun 11, 2002
* copyright : (C) 2001 The phpBB Group
*
*
* Modifyed vesion 1.0.11.
* added Custom mass email
*
* History:
* 1.0.0 - initial release
* 1.0.2 - fixed a minor bug, the displayed userlist for all users was not correct
* 1.0.3 - improved security
* 1.0.4 - fixed a bug introduced in version 1.0.3, causing not autorized to send to ALL
* 1.0.5 - now only fetch the number of users specifyed in the MAX_CLIENT_IN_EMAIL from the DB
* 1.0.6 - updated the emailer protocol to handle more types of (E)SMTP servers
* 1.0.7 - nowsupport mass email permissions
* 1.0.8 - security update
* 1.0.9 - added support for direct linked mass email, e.g. www.yoursite.com/mass_email.php?groupname=newsletter (group name is case sensitive)
* 1.0.10. - fix, change || to &&
* 1.0.11. - unroll the 1.0.10
*
* 1.0.12 - conversion to admin_mass_email.php for admin only mass mailing.
****************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', 1);
// ###############################
// Here you can define how large the emails are to be, when sending them out
define('MAX_CLIENT_IN_EMAIL', 100);
if( !empty($setmodules) )
{
$filename = basename(__FILE__);
$module['General']['Mass_Email'] = $filename;
return;
}
//
// Load default header
//
$no_page_header = TRUE;
$phpbb_root_path = './../';
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
//
// Generate page
//
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_mass_email.' . $phpEx);
$page_title = $lang['Mass_Email'];
//
// Increase maximum execution time in case of a lot of users, but don't complain about it if it isn't
// allowed.
//
@set_time_limit(120);
$message = "";
$subject = "";
//
// Do the job ...
//
if( isset($HTTP_POST_VARS['submit']) )
{
$group_id = intval($HTTP_POST_VARS[POST_GROUPS_URL]);
if( $group_id != -1 )
{
$sql = "SELECT DISTINCT g.group_name
FROM ".GROUPS_TABLE . " g, ".USER_GROUP_TABLE . " ug
WHERE g.group_single_user <> 1 AND g.group_id='".$group_id."'
AND (
('".$userdata['user_level']."'='".ADMIN."') OR
(g.group_allow_email='".AUTH_MOD."' AND g.group_moderator = '" . $userdata['user_id']."') OR
(g.group_allow_email='".AUTH_ACL."' AND ug.user_id = " . $userdata['user_id'] . " AND ug.group_id = g.group_id ) OR
(g.group_allow_email='".AUTH_REG."' AND '".$userdata['user_id']."'!='-1' ) OR
(g.group_allow_email='".AUTH_ALL."')
)" ;
if( !$g_result = $db->sql_query($sql) )
message_die(GENERAL_ERROR, "Could not select group names!", __LINE__, __FILE__, $sql);
if( ! $db->sql_numrows($g_result)) message_die(GENERAL_ERROR, $lang['Not_Authorised']);
$group = $db->sql_fetchrow($g_result);
$group_name=$group['group_name'];
$sql = "SELECT distinct u.user_email, u.user_lang, u.username, u.user_id
FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, ". GROUPS_TABLE . " g
WHERE ug.group_id = $group_id
AND ug.user_pending <> " . TRUE . "
AND u.user_id = ug.user_id AND u.user_email <> ''
ORDER BY u.user_lang";
$sql2="SELECT COUNT(distinct u.user_id) AS num_emails
FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, ". GROUPS_TABLE . " g
WHERE ug.group_id = $group_id
AND ug.user_pending <> " . TRUE . "
AND u.user_id = ug.user_id AND u.user_email <> ''";
}
else
{
if( $userdata['user_level']!=ADMIN ) message_die(GENERAL_ERROR, $lang['Not_Authorised']);
$sql = "SELECT user_email, user_lang, username, user_id
FROM " . USERS_TABLE." WHERE user_email <> '' ORDER BY user_lang";
$sql2="SELECT COUNT(user_id) AS num_emails FROM " . USERS_TABLE." WHERE user_email <> ''";
}
if( !$result2 = $db->sql_query($sql2) )
{
message_die(GENERAL_ERROR, "Coult not count group members!", __LINE__, __FILE__, $sql2);
}
$num_emails = $db->sql_fetchrow($result2);
$num_emails=$num_emails['num_emails'];
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$offset=0;
$name_list='';
$sendt_to='';
$email_counter=0;
$num_users=0;
while ($offset < $num_emails)
{
$sql_current = $sql." LIMIT ".$offset.",".MAX_CLIENT_IN_EMAIL;
$db->sql_freeresult($result);
if( !$result = $db->sql_query($sql_current) )
{
message_die(GENERAL_ERROR, "Coult not select group members!", __LINE__, __FILE__, $sql_current);
}
if( ! $db->sql_numrows($result))
{
$email_list = $db->sql_fetchrowset($result);
message_die(GENERAL_ERROR, "Coult not find any group members!", __LINE__, __FILE__, $sql_current);
}
$email_list = $db->sql_fetchrowset($result);
$subject = stripslashes($HTTP_POST_VARS["subject"]);
$message = stripslashes($HTTP_POST_VARS["message"]);
//
// Error checking needs to go here ... if no subject and/or
// no message then skip over the send and return to the form
//
$error = FALSE;
if( !$error )
{
$server_name = ( isset($HTTP_SERVER_VARS['HTTP_HOST']) ) ? $HTTP_SERVER_VARS['HTTP_HOST'] : $HTTP_SERVER_VARS['SERVER_NAME'];
$protocol = ( !empty($HTTP_SERVER_VARS['HTTPS']) ) ? ( ( $HTTP_SERVER_VARS['HTTPS'] == "on" ) ? "https://" : "http://" ) : "http://";
//
// Let's do some checking to make sure that mass mail functions
// are working in win32 versions of php.
//
if( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
{
// We are running on windows, force delivery to use
// our smtp functions since php's are broken by default
$board_config['smtp_delivery'] = 1;
$board_config['smtp_host'] = get_cfg_var('SMTP');
}
$i=0;
while ($i<count($email_list))
{
$email_headers='';
if ($current_lang!=$email_list[$i]['user_lang'] && $num_users<>0)
{
$send_result .= sprintf ( $lang['Mass_email_count'],$language_counter,$current_lang).' <br/>';
$sendt_to .= '<p>'.sprintf($lang['Sendt_to'],$current_lang).'<br/> '.$name_list.'</p>';
$name_list='';
$language_counter='';
}
$current_lang=$email_list[$i]['user_lang'];
$emailer = new emailer($board_config['smtp_delivery']);
if (file_exists($phpbb_root_path . "language/lang_" . $current_lang . "/email/custom_email_".$group_name.".tpl"))
{
$emailer->use_template("custom_email_".$group_name, $current_lang);
}
else
{
if (file_exists($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/email/custom_email_".$group_name.".tpl"))
{
$emailer->use_template("custom_email_".$group_name,$board_config['default_lang']);
} else
{
$emailer->use_template("admin_send_email", $current_lang);
}
}
$emailer->email_address($userdata['user_email']);
$username_list = '';
$bcc_list="";
$n=0;
while ($email_list[$i]['user_lang']==$current_lang && $i<count($email_list))
{
if(!empty($bcc_list)) $bcc_list .= ", ";
$bcc_list .= $email_list[$i]['user_email'];
if(!empty($name_list)) $name_list .= ", ";
$name_list .= "<a href=".append_sid($phpbb_root_path."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $email_list[$i]['user_id']).">".$email_list[$i]['username']."<a>";
$username_list .= (($username_list) ? ', ':'').$email_list[$i]['username'];
$i++;
$num_users++;
$n++;
$language_counter++;
}
// re- increase time limit
@set_time_limit(60);
$email_counter++;
$email_headers .= "From: \"".$board_config['sitename']."\" <".$board_config['board_email'].">\r\n";
$email_headers .= ($userdata['user_email']&&$userdata['user_viewemail'])? "Return-Path: \"".$userdata['username']."\" <".$userdata['user_email'].">\r\n":"";
$email_headers .= "X-AntiAbuse: Board servername - " . $server_name . "\r\n";
$email_headers .= "X-AntiAbuse: User_id - " . $userdata['user_id'] . "\r\n";
$email_headers .= "X-AntiAbuse: Username - " . $userdata['username'] . "\r\n";
$email_headers .= "X-AntiAbuse: User IP - " . decode_ip($user_ip) . "\r\n";
$email_headers .= "Bcc: $bcc_list\r\n";
$emailer->email_address($userdata['user_email']);
$emailer->set_subject($subject);
$emailer->extra_headers($email_headers);
$emailer->assign_vars(array(
"GROUPNAME" => $group_name,
"UNSUBSCRIBE" => $unsubscribe,
"SITENAME" => $board_config['sitename'],
"BOARD_EMAIL" => $board_config['board_email'],
"USERNAME_LIST" => $username_list,
"MESSAGE" => $message));
$emailer->send();
$emailer->reset();
unset ($emailer);
echo sprintf ( $lang['Mass_email_count'],$n,$current_lang).' <br/>';
flush();
}
$offset = $offset + MAX_CLIENT_IN_EMAIL;
}
}
$send_result .= sprintf ( $lang['Mass_email_count'],$language_counter,$current_lang).' <br/>';
$sendt_to .= '<p>'.sprintf($lang['Sendt_to'],$current_lang).'<br/> '.$name_list.'</p>';
$send_result .= sprintf ($lang['Mass_email_total'],$num_users,$email_counter).'<br/>';
$message = $lang['Email_sent'] . "<br />$send_result<br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>").$sendt_to;
message_die(GENERAL_MESSAGE, $message);
}
//
// Initial selection
//
$sql = "SELECT DISTINCT g.group_id, g.group_name
FROM ".GROUPS_TABLE . " g, ".USER_GROUP_TABLE . " ug
WHERE g.group_single_user <> 1
AND (
('".$userdata['user_level']."'='".ADMIN."') OR
(g.group_allow_email='".AUTH_MOD."' AND g.group_moderator = '" . $userdata['user_id']."') OR
(g.group_allow_email='".AUTH_ACL."' AND ug.user_id = " . $userdata['user_id'] . " AND ug.group_id = g.group_id ) OR
(g.group_allow_email='".AUTH_REG."' AND '".$userdata['user_id']."'!='-1' ) OR
(g.group_allow_email='".AUTH_ALL."')
)" ;
if( !$g_result = $db->sql_query($sql) )
message_die(GENERAL_ERROR, "Could not select group names!", __LINE__, __FILE__, $sql);
$group_list = $db->sql_fetchrowset($g_result);
if( $userdata['user_level']!=ADMIN && empty($group_list)) message_die(GENERAL_ERROR, $lang['Mass_email_not_allowed']);
$groupname = trim(strip_tags($HTTP_GET_VARS['groupname']));
$select_list = '<select name = "' . POST_GROUPS_URL . '">';
$select_list .= ($userdata['user_level']==ADMIN) ? '<option value = "-1" '. (($lang['All_users']==$groupname) ? ' SELECTED ' : '' ).'>' . $lang['All_users'] .'</option>':'';
for($i = 0;$i < count($group_list); $i++)
{
$select_list .= '<option value = "' . $group_list[$i]['group_id'].'"'. (($group_list[$i]['group_name']==$groupname)? ' SELECTED ' : '').'>'.$group_list[$i]['group_name'] .'</option>';
}
$select_list .= "</select>";
//$select_list = '<select name = "' . POST_GROUPS_URL . '">';
//$select_list .= ($userdata['user_level']==ADMIN) ? '<option value = "-1">' . $lang['All_users'] . '</option>':'';
//for($i = 0;$i < count($group_list); $i++)
//{
// $select_list .= "<option value = \"" . $group_list[$i]['group_id'];
// $select_list .= "\">" . $group_list[$i]['group_name'] . "</option>";
//}
//$select_list .= "</select>";
//
// Generate page
//
include('./page_header_admin.'.$phpEx);
$template->set_filenames(array(
"body" => "admin/user_email_body.tpl")
);
$template->assign_vars(array(
"MESSAGE" => $message,
"SUBJECT" => $subject,
"L_EMAIL_TITLE" => $lang['Email'],
"L_EMAIL_EXPLAIN" => $lang['Mass_email_explain'],
"L_COMPOSE" => $lang['Compose'],
"L_RECIPIENTS" => $lang['Recipients'],
"L_EMAIL_SUBJECT" => $lang['Subject'],
"L_EMAIL_MSG" => $lang['Message'],
"L_EMAIL" => $lang['Email'],
"L_NOTICE" => $notice,
"S_USER_ACTION" => append_sid('mass_email.'.$phpEx),
"S_GROUP_SELECT" => $select_list)
);
$template->pparse('body');
include('./page_footer_admin.'.$phpEx);
?>

