1
Plugins / [PLUGIN] Massmailer/Batch Mailer
« on: January 03, 2008, 10:30:42 PM »
Save it as email.php, massmailer.php or what ever and put it into your /admin/plugins/ folder...
Please try it and give me Feedback...
I have not enough Users in on my Test System... (o:
Code: [Select]
<?php // PLUGIN_TITLE: Massmailer
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: email.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.1 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) fr weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
$nozip = 1;
define('IN_CP', 1);
$PHP_SELF = (isset($PHP_SELF)) ? $PHP_SELF : $_SERVER['PHP_SELF'];
$root_path = (eregi("\/plugins\/", $PHP_SELF)) ? "./../../" : "./../";
define('ROOT_PATH', $root_path);
require(ROOT_PATH.'admin/admin_global.php');
// TEXT
define('MASSMAIL_TITEL', "Emails an User versenden");
define('MASSMAIL_MAXMAILS', "Anzahl der Mails die verschickt werden sollen");
define('MASSMAIL_BREAK', "Pause (sec.)");
define('MASSMAIL_AUTOREDIRECT', "Automatische Weiterleitung");
define('MASSMAIL_USERLEVEL', "Userlevel");
define('MASSMAIL_SUBJECT', "Betreff");
define('MASSMAIL_MESSAGE', "Nachricht");
define('MASSMAIL_BUTTON_SEND', "E-Mails an User versenden");
define('MASSMAIL_SUBJECT2', "Betreff (%=wildcard)");
define('MASSMAIL_MESSAGE2', "Nachricht (%=wildcard)");
define('MASSMAIL_LIMITFROM', "Starte bei:");
define('MASSMAIL_SENDTO', "<b>Mail an folgende User: </b>");
define('MASSMAIL_DONE', "<b>Alle Mails dieser Usergruppe wurden erfolgreich versendet... </b>");
// CONFIG
$config_break = 3;
$config_maxemails = 2;
$config_default_subject = "Betreff...";
$config_default_message = "Nachricht...";
if ($action == "") {
$action = "emailusers";
}
show_admin_header();
if ($action == "sendemails") {
$error = array();
$maxemails = stripslashes(trim($_REQUEST['maxemails']));
$break = stripslashes(trim($_REQUEST['break']));
$autoredirect = stripslashes(trim($_REQUEST['autoredirect']));
$user_level = $_REQUEST['user_level'];
$subject = stripslashes(trim($_REQUEST['subject']));
$message = stripslashes(trim($_REQUEST['message']));
if ($maxemails == "") {
$error['maxemails'] = 1;
}
if ($break == "") {
$error['break'] = 1;
}
if ($user_level <= 0 || $user_level == "") {
$error['user_level'] = 1;
}
if ($subject == "") {
$error['subject'] = 1;
}
if ($message == "") {
$error['message'] = 1;
}
if (empty($error)) {
// SQL Limit
if (isset($_REQUEST['limitfrom'])) {
$limitfrom = $_REQUEST['limitfrom'];
$limitfrom = $limitfrom + $maxemails;
}else{
$limitfrom = 0;
}
if (isset($_REQUEST['i'])) {
$i = $_REQUEST['i'];
}else {
$i = 0;
}
define("PM_LIMIT", "DESC LIMIT ".$limitfrom." , ".$maxemails);
// SQL Limit Ende
//Where definieren
define('WHERE_ID', "WHERE user_level = '".$user_level."'");
// Mailaddi aus der Datenbank holen
global $site_db;
$sql = "SELECT user_email, user_name
FROM ".USERS_TABLE."
".WHERE_ID." AND ".get_user_table_field("", "user_allowemails")." = 1
ORDER BY user_id
".PM_LIMIT;
$result = $site_db->query($sql);
$num_of_rows = mysql_num_rows($result);
//SQL Debug
//echo $sql."<br>";
//Empfnger
$emails = array();
echo MASSMAIL_SENDTO."<br>";
while($row = $site_db->fetch_array($result)){
// Username (E-Mail) ausgeben
echo " ".$i++." - ".$row["user_name"]." (".$row["user_email"].")<br>";
array_push($emails, $row["user_email"]);
}
//Empfnger Ende
//E-Mail
include(ROOT_PATH.'includes/email.php');
$site_email = new Email();
$site_email->set_to($config['site_email']);
$site_email->set_subject($subject);
$site_email->register_vars(array(
"message" => $message,
"site_email" => $config['site_email'],
"site_name" => $config['site_name']
));
$site_email->set_body("admin_email", $config['language_dir']);
$site_email->set_bcc($emails);
echo ($site_email->send_email()) ? $lang['send_emails_success'] : $lang['send_emails_error'];
unset($site_email);
//E-Mail Ende
//Alle Mails versendet
if ($num_of_rows < $maxemails) {
$autoredirect= false;
echo "<br><br>".MASSMAIL_DONE."<br><br>";
}
//Formular ausgeben
show_form_header("email.php", "sendemails");
show_table_header(MASSMAIL_TITEL, 2);
show_input_row(MASSMAIL_LIMITFROM, "limitfrom", $limitfrom, 3);
show_input_row(MASSMAIL_MAXMAILS, "maxemails", $maxemails, 5);
show_input_row(MASSMAIL_BREAK, "break", $break, 5);
show_radio_row(MASSMAIL_AUTOREDIRECT, "autoredirect", 1);
show_userlevel_select_row(MASSMAIL_USERLEVEL, "user_level", $user_level);
show_input_row(MASSMAIL_SUBJECT, "subject", $subject, 45);
show_textarea_row(MASSMAIL_MESSAGE, "message", $message, 60, 20);
show_form_footer(MASSMAIL_BUTTON_SEND, "", 2);
if ($autoredirect) {
$page = $site_sess->url($_SERVER['PHP_SELF']."?action=sendemails&limitfrom=".$limitfrom."&maxemails=".$maxemails."&break=".$break."&user_level=".$user_level."&i=".$i."&autoredirect=".$autoredirect."&subject=".$subject."&message=".$message);
?>
<script language="javascript">
myvar = "";
timeout = <?php echo $break ?>;
function dorefresh() {
window.status="Redirecting"+myvar;
myvar = myvar + " .";
timerID = setTimeout("dorefresh();", 1000);
if (timeout > 0) {
timeout -= 1;
}
else {
clearTimeout(timerID);
//document.formular.submit()
window.status="";
window.location="<?php echo $page; ?>";
}
}
dorefresh();
</script>
<?php
}
}else {
$msg = sprintf("<span class=\"marktext\">%s</span>", $lang['lostfield_error']);
$action = "emailusers";
}
}
if ($action == "emailusers") {
if ($msg != "") {
printf("<b>%s</b>\n", $msg);
}
show_form_header("email.php", "sendemails");
show_table_header(MASSMAIL_TITEL, 2);
show_input_row(MASSMAIL_MAXMAILS, "maxemails", $config_maxemails, 5);
show_input_row(MASSMAIL_BREAK, "break", $config_break, 5);
show_radio_row(MASSMAIL_AUTOREDIRECT, "autoredirect", 1);
show_userlevel_select_row(MASSMAIL_USERLEVEL, "user_level", $user_row['user_level']);
show_input_row(MASSMAIL_SUBJECT, "subject", $config_default_subject, 45);
show_textarea_row(MASSMAIL_MESSAGE, "message", $config_default_message, 60, 20);
show_form_footer(MASSMAIL_BUTTON_SEND, "", 2);
}
show_admin_footer();
?>
Please try it and give me Feedback...
I have not enough Users in on my Test System... (o: