Email Blast

Hi, I’ve had to create an email blast and database for my work for us to send emailers. We sent the first one a few days ago and have received a small handful of emails from people saying that they have received it between 10 - 20 times. I have checked the database and indeed there were quite a few duplicate email address most have been dupliced two or three times.

In my script, I set an enum for when each address is process so I’m guessing theoretically no one should receive it more than once. I have now removed all of the duplicates and there is only one address per person.

I woke up in the morning and noticed now 7,205 addresses had received the emailer so tried sending it again so I’m wondering if that’s what done it - though the vast majority had the enum set to 1 which is good. Just making sure for next time that all is good to send and hopefully a small handful WILL NOT receive 10 - 20 copies of the emailer.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bulk Email Control Panel</title>
<link rel="stylesheet" type="text/css" href="controlstyles.css" />
<div class="contOuter">
<div class="contInner">
echo '<fieldset><legend>Emailer Sending Status<div class="container"><img src="loading.png" class="textmiddle" width="16" height="16" /><span class="large"> Emailer is currently sending...</span></div>'; flush();

include_once "connection.php";
$sql = mysql_query("SELECT * FROM addresses WHERE received='0'");
$count = mysql_query("SELECT COUNT(*), `received` FROM `addresses` GROUP BY `received`");
$count1 =  mysql_fetch_row($count);
$result = mysql_query("SELECT * FROM addresses");
$num_rows = mysql_num_rows($result);

$numRows = mysql_num_rows($sql); 
$mail_body = '';
while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$email = $row["email"];
	$mail_body = $htmlContent;
    $subject = "$subject";
    $headers  = "\\r\
    $headers .= "Content-type: text/html\\r\
    $to = "$email";

    $mail_result = mail($to, $subject, $mail_body, $headers);
	if ($mail_result) {
		mysql_query("UPDATE addresses SET received='1' WHERE email='$email' LIMIT 1");
	} else {

echo '<div class="large" style="color:#009900; font-weight: bold; margin: 0px 0px 0px 19px;">Emailer has been sent.</div>';
echo "<span style='margin:0px 0px 0px 19px;'>Emailer sent to $count1[0] of the $num_rows email addresses in the database.</span></legend></fieldset><br/>

<legend>Reset Emailer Status</legend>
<form name='newsletter' action='reset-database.php' method='post'>
<input name='submit' type='submit' id='submit' value='Reset Emailer Database' /></form></fieldset><br/>
Now that the emailer has been successfully sent, the database needs to be reset in order to send out the next emailer. Please click the above <span style='font-weight: bold;'>Reset Emailer Database</span>. This will not resend an emailer or delete or screw anything up in the database.
	 if (!$numRows == 0) {
	 $subj = "Newsletter Campaign Has Ended";
	 $body = "<span style='color: #FF0000; font-weight: bold;'>The current newsletter campaign has ended.</span> Emailer sent to <strong>$count1[0]</strong> of the <strong>$num_rows</strong> email addresses in the database.";
     $hdr  = "\\r\
     $hdr .= "Content-type: text/html\\r\
     mail("$success", $subj, $body, $hdr);


<?php include('tpl_includes/footer.php'); ?>

  `id` int(11) NOT NULL auto_increment,
  `email` varchar(50) NOT NULL,
  `datetime` datetime NOT NULL,
  `received` enum('0','1') NOT NULL,
  PRIMARY KEY  (`id`)

Does anyone know if this will do the job? I’ve used it once and it seems work ok. Just want to see what others think of it.