i have problem with a bulk email script. everything works fine by getting the email addresses and sending an html email... every 1 second using sleep, then sleeping for 10 seconds after sending a batch of 30.
now what i want to do is insert its email address as a tracking code into each mail. here's the unmodified code...
when i modify the code by doing this...
$mailbody .= '<img src="image.php?id='.$EmailAddress2[$i].'">';
what i get is a loop of all the email addresses in each html email. what am i doing wrong?
now what i want to do is insert its email address as a tracking code into each mail. here's the unmodified code...
Code:
//query email addresses from db
$SQL = "SELECT * ";
$SQL .= "FROM email_list ";
$SQL .= "WHERE store_code = '$category' ";
if(!$result = mysql_query($SQL)) die("Query died for $SQL");
while($row = mysql_fetch_array($result))
{
//collect emails in array
$EmailAddress2[] = $row["email"];
}
$mailbody = stripslashes($content);
$max= count($EmailAddress2);
$hold=0;
$letters_sent=0;
$notsent=0;
set_time_limit(0);
for ($i=0; $i < ($max); $i++) {
if(mail($EmailAddress2[$i], $subject2, $mailbody, $headers)) {
$hold++;
$letters_sent++;
echo($EmailAddress2[$i]." <b>sent!</b><br />");
//there should be a 1 second delay between emails.
sleep(1);
if($hold==30) { //if 30 emails sent - code rest for 10 seconds then execute after
sleep(10);
$hold=0;
}
} else {
$notsent++;
echo($EmailAddress2[$i]." <font color=\"#ff0000\"><b>not sent</b></font><br />");
// end if
}
// end for
}
$sentstatus="<p>Newsletter sent!</p>";
?>
<b><?=$letters_sent?></b> newsletters sent
<br>
<b><?=$notsent?></b> newsletters failed
when i modify the code by doing this...
Code:
$hold=0;
$letters_sent=0;
$notsent=0;
set_time_limit(0);
for ($i=0; $i < ($max); $i++) {
$mailbody .= '<img src="image.php?id='.$EmailAddress2[$i].'">';
if(mail($EmailAddress2[$i], $subject2, $mailbody, $headers)) {
$hold++;
$letters_sent++;
echo($EmailAddress2[$i]." <b>sent!</b><br />");
//there should be a 1 second delay between emails.
sleep(1);
if($hold==30) { //if 30 emails sent - code rest for 10 seconds then execute after
sleep(10);
$hold=0;
}
} else {
$notsent++;
echo($EmailAddress2[$i]." <font color=\"#ff0000\"><b>not sent</b></font><br />");
// end if
}
// end for
}
$mailbody .= '<img src="image.php?id='.$EmailAddress2[$i].'">';
what i get is a loop of all the email addresses in each html email. what am i doing wrong?