[56K WARN] Mailing List Problems - Double Posting?
Posted: Tue Mar 21, 2006 9:13 pm
For some strange reason, my mailing list script just started emailing everything twice. Here's the code, and the output; also, I had it try to email me, and I do indeed get two emails.
And here's what happens when I execute the script:

(Please excuse the silly blurring!)
Code: Select all
<?
if ($action == 'load'){
include("../scripts/_config.php");
$sqlhost = $db_host;
$sqllogin = $db_user;
$sqlpass = $db_pass;
$sqldb = $db_name;
$sqlquery = "SELECT email FROM mailinglist WHERE 1 LIMIT 0,65550";
if (!$sqlhost || !$sqllogin || !$sqlpass || !$sqldb || !$sqlquery){
print "Please configure mailinglistinfo.php with your MySQL information. All settings in this config file are required.";
exit; }
$db = mysql_connect($sqlhost, $sqllogin, $sqlpass) or die("Connection to MySQL Failed.");
mysql_select_db($sqldb, $db) or die("Could not select database $sqldb");
$result = mysql_query($sqlquery) or die("Query Failed: $sqlquery");
$numrows = mysql_num_rows($result);
for($x=0; $x<$numrows; $x++) {
$result_row = mysql_fetch_row($result);
$oneemail = $result_row[0];
$emaillist .= $oneemail."\n"; }
if ($action=="send") {
$message = urlencode($message);
$message = ereg_replace("%5C%22", "%22", $message);
$message = urldecode($message); $message = stripslashes($message); $subject = stripslashes($subject);
}}
?>
<form name="mailer" method="post" action="" enctype="multipart/form-data">
<table width="478" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/main/top1.gif" width="20" height="32"></td>
<td background="../images/main/top2.gif" height="32">
<!-- Top -->
<strong>Sent Mail</strong></td>
<td background="../images/main/top3.gif" width="20" height="32"></td>
</tr>
<tr>
<td background="../images/main/left.gif" width="20">
<!-- Left Side -->
</td>
<td bgcolor="#000000">
<?
if ($action=="send"){
if (!$from && !$subject && !$message && !$emaillist){
print "Please complete all fields before sending your message.";
exit;
}
$allemails = split("\n", $emaillist);
$numemails = count($allemails);
#Open the file attachment if any, and base64_encode it for email transport
If ($file_name){
@copy($file, "./$file_name") or die("The file you are trying to upload couldn't be copied to the server");
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = basename($file);
}
for($x=0; $x<$numemails; $x++){
$to = $allemails[$x];
if ($to){
$to = ereg_replace(" ", "", $to);
$message = ereg_replace("&email&", $to, $message);
$subject = ereg_replace("&email&", $to, $subject);
print "Sending mail to $to...";
flush();
$header = "From: $realname <$from>\r\nReply-To: $replyto\r\n";
$header .= "MIME-Version: 1.0\r\n";
If ($file_name) $header .= "Content-Type: multipart/mixed; boundary=$uid\r\n";
If ($file_name) $header .= "--$uid\r\n";
$header .= "Content-Type: text/$contenttype\r\n";
$header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$header .= "$message\r\n";
If ($file_name) $header .= "--$uid\r\n";
If ($file_name) $header .= "Content-Type: $file_type; name=\"$file_name\"\r\n";
If ($file_name) $header .= "Content-Transfer-Encoding: base64\r\n";
If ($file_name) $header .= "Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n";
If ($file_name) $header .= "$content\r\n";
If ($file_name) $header .= "--$uid--";
mail($to, $subject, "", $header);
print "success!<br />";
flush();
}
}
}
?>
</td>
<td background="../images/main/right.gif" width="20">
<!-- Right Side -->
</td>
</tr>
<tr>
<!-- Bottom -->
<td background="../images/main/bottom1.gif" width="20" height="17"></td>
<td background="../images/main/bottom2.gif" height="17"></td>
<td background="../images/main/bottom3.gif" width="20" height="17"></td>
</tr>
</table>
<table width="478" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/main/top1.gif" width="20" height="32"></td>
<td background="../images/main/top2.gif" height="32">
<!-- Top -->
<strong>Information</strong></td>
<td background="../images/main/top3.gif" width="20" height="32"></td>
</tr>
<tr>
<td background="../images/main/left.gif" width="20">
<!-- Left Side -->
</td>
<td bgcolor="#000000">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="75">Email:</td>
<td colspan="2"><input type="text" name="from" value="MailingList@TBMChicago.com" size="30">
</td>
</tr>
<tr>
<td>Reply-To:</td>
<td colspan="2"><input type="text" name="replyto" value="MailingList@TBMChicago.com" size="30">
</td>
</tr>
<tr>
<td>Name:</td>
<td colspan="2"><input type="text" name="realname" value="TBMChicago Mailing List" size="30"></td>
</tr>
<tr>
<td>Attach:</td>
<td colspan="2"><input type="file" name="file" size="30"></td>
</tr>
<tr>
<td>Subject:</td>
<td colspan="2"><input type="text" name="subject" value="<? print $subject; ?>" size="50">
</td>
</tr>
<tr>
<td valign="top">To:</td>
<td colspan="2"><textarea name="emaillist" cols="38" rows="4"><? print $emaillist; ?></textarea><br>
<a href="index.php?function=mailinglist&action=load">Load Addresses</a>
</td>
</tr>
</table>
</td>
<td background="../images/main/right.gif" width="20">
<!-- Right Side -->
</td>
</tr>
<tr>
<!-- Bottom -->
<td background="../images/main/bottom1.gif" width="20" height="17"></td>
<td background="../images/main/bottom2.gif" height="17"></td>
<td background="../images/main/bottom3.gif" width="20" height="17"></td>
</tr>
</table>
<table width="478" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/main/top1.gif" width="20" height="32"></td>
<td background="../images/main/top2.gif" height="32">
<!-- Top -->
<strong>Message</strong></td>
<td background="../images/main/top3.gif" width="20" height="32"></td>
</tr>
<tr>
<td background="../images/main/left.gif" width="20">
<!-- Left Side -->
</td>
<td bgcolor="#000000">
<p>To send mail, first hit "Load Addresses" and then type your message. Finally,
click send. If successful, the Sent Mail box will list the email addresses sent to
as it sends the message.</p>
<p>Message:<br>
<textarea name="message" cols="48" rows="8"><? print $message; ?>
---------
This email has been sent to you because you subscribed to the TBMChicago mailing list. To unsubscribe to this list, email eric@tbmchicago.com.
</textarea><br>
<input type="radio" name="contenttype" value="plain" checked> Plain
<input type="radio" name="contenttype" value="html"> HTML
<input type="hidden" name="action" value="send">
<input type="submit" value="Send Message"> </p>
</td>
<td background="../images/main/right.gif" width="20">
<!-- Right Side -->
</td>
</tr>
<tr>
<!-- Bottom -->
<td background="../images/main/bottom1.gif" width="20" height="17"></td>
<td background="../images/main/bottom2.gif" height="17"></td>
<td background="../images/main/bottom3.gif" width="20" height="17"></td>
</tr>
</table>
</form>
(Please excuse the silly blurring!)