<?php
require("phpmailer/class.phpmailer.php");
require("config.php");
$auth = 0;
if ( ($_SERVER['PHP_AUTH_USER'] == $username) && ($_SERVER['PHP_AUTH_PW'] == $password) ) {!
$auth = 1;
}
if ($auth != 1) {
header('WWW-Authenticate: Basic realm="Mail Blaster"');
header('HTTP/1.0 401 Unauthorized');
echo 'You will need to login to blast mail';
exit;
}
// If no file name was specified, we must not continue with rest of script
if (empty($saveasname)) {
print "<br><font color=red>Error - File name at bottom must be filled out. Please make sure you either type a new name in or load a file from the \"Saved Message\" menu.<br><a href=\"javascript:history.back();\">Click here to go back</a><br>\n";
exit();
}
// TODO - if coming from index page, must check that all required fields are filled in - see prewivew.php
// First things first, we now save contents of $newmessage (the textarea)
// to $saveasname
if (ereg("index\.php", $_SERVER["HTTP_REFERER"])) {
$fp = fopen($messagedir.$saveasname, 'w');
if (fwrite($fp, stripslashes($newmessage))) {
$savedmessage = $saveasname;
}
else {
print "<br><font color=red>Error saving new file</font><br>\n";
}
fclose($fp);
}
elseif (ereg("preview\.php", $_SERVER["HTTP_REFERER"])) {
// We have already saved the latest version in the preview page
}
// Load the mailing list
if ($maillist != "") {
$listfile = $listsdir . $maillist;
}
elseif (isset($maillist_new)) {
$listfile = $listsdir . $_FILES['maillist_new']['name'];
if (!move_uploaded_file($_FILES['maillist_new']['tmp_name'], $listfile)) {
print "Error uploading file: ";
print_r($_FILES);
}
}
$addresses = file($listfile);
// Load the message
if (!empty($_FILES['uploadmessage']['name'])) {
$messagefile = $messagedir . $_FILES['uploadmessage']['name'];
if (move_uploaded_file($_FILES['uploadmessage']['tmp_name'], $messagefile)) {
$fp = fopen($messagefile, "r");
$message_contents = fread($fp, filesize($messagefile));
fclose($fp);
}
else {
print_r($_FILES);
}
}
elseif (!empty($savedmessage)) {
$messagefile = $messagedir . $savedmessage;
$fp = fopen($messagefile, "r");
$message_contents = fread($fp, filesize($messagefile));
fclose($fp);
}
elseif (!empty($newmessage)) {
$message_contents = $newmessage;
}
// Send out message and print reports
if ($type == "plaintext") {
$headers = "From: " . $from . "\r\n" . "Reply-To: " . $from . "\r\n" . "X-Mailer: mailblaster.php";
for ($i=0; $i<sizeOf($addresses); $i++) {
// TODO see if phpmailer has checking
// if not then use validate from mail2 on piranha
//if (eregi("(\w+[\w|\.]*\w+)(@\w+[\w|\.]*\w+\.\w{2,3})", $addresses[$i])) {
if (true) {
if ($include_removal) $removal_text = removal_text($addresses[$i], $maillist, "plaintext");
if (!mail($addresses[$i], $subject, $message_contents . $removal_text, $headers)) {
print "<font color=red face=Verdana>";
print "Problem sending mail using mail() to " . $addresses[$i] . "<BR>\n";
print "</font>";
}
else {
print "<font color=green face=Verdana>";
print "Message sent via mail() to " . $addresses[$i] . "<BR>\n";
print "</font>";
}
}
else {
print "<font color=yellow face=Verdana>WARNING: Bad email found: " . $addresses[$i] . "</font><BR>";
}
}
}
elseif ($type == "html") {
$mail = new PHPMailer();
for ($i=0; $i<sizeOf($addresses); $i++) {
$addresses[$i] = rtrim($addresses[$i]);
$addresses[$i] = ltrim($addresses[$i]);
//if (eregi("(\w+[\w|\.]*\w+)(@\w+[\w|\.]*\w+\.\w{2,3})", $addresses[$i])) {
//if (ereg("^([A-Za-z_\.]*)@([A-Za-z_]*)\.([A-Za-z_\.]*)$", $string)) {
if (true) {
$mail->From = $from;
$mail->FromName = $from;
$mail->Host = "localhost";
$mail->Mailer = "smtp";
$mail->AddAddress($addresses[$i]);
$mail->Subject = $subject;
$mail->isHTML(true);
if ($include_removal) $removal_text = removal_text($addresses[$i], $maillist, "html");
$mail->Body = $message_contents . $removal_text;
$mail->AltBody = "This would be the text version of the HTML mail";
if (!$mail->Send()) {
print "<font color=red face=Verdana>";
print "Problem sending mail using PHPMailer to " . $addresses[$i] . "<BR>\n";
print "</font>";
unset($mail);
$mail = new PHPMailer();
}
else {
print "<font color=green face=Verdana>";
print "Message sent via PHPMailer to " . $addresses[$i] . "<BR>\n";
print "</font>";
}
$mail->ClearAddresses();
//$mail->ClearAttachments();
}
else {
print "<font color=yellow face=Verdana>WARNING: Bad email found: " . $addresses[$i] . "</font><BR>";
}
}
}
?>
<br><br>
<font face="verdana">If you don't see any errors, then it's all good. Otherwise, panic.
<br><br>
<a href="index.php">Click here to go back to Main Page</a></font>
<br><br>