The code below is designed to loop through rows of a database query
obtaining email addresses and send an email to each. It is modified form
fomr some code I found on the net.
With each while loop, it updates the SENT field of the processed row to mark
it sent. I have a sleep function in there to slow the processing down to
see if that alleviated the following problem - it did help.
What is happening is the first 20 emails it sends correctly. Then it starts
sending with no $subject or $message but the remove form list text is still
in the email. When I did it for a client, some clients ending up geting 5
blank emails and one good email. It was bizarre and not uniformly wrong.
When I send it, I follow the progress in almost real time by monitoring the
test email account. When it started sending blank emails, I stop the web
form used for sending.
After I stopped it, I have about 35 emails. The database has about 1000
addresses. However, the database shows that ALL rows' sent field were
updated.
Any ideas of how to improve or rewrite this to work? Could it be that it is
on a shared server and there's something going on there?
Many thanks for your help!
<?
$subject = $_POST[subject];
$message = $_POST[message];
$sql2 = "select address from email_table";
$res2 = mysql_query($sq l2) or die("Couldn't get addresses.");
$headers = "From: \"".FROMNAME."\ " <".FROMEMAIL."> \r\n"; //from a config
file
$email['fromemail'] = "me@mydomain.co m";
$headers .="Return-Path: <me@mydomain.co m>\r\n";
while ($row = mysql_fetch_arr ay($res2)) {
$email_addr = $row[0];
if (INSERTLINK == "true") {
$fullmessage = $message . "
-------------------------------------------------------
If you would like to remove yourself from this list and receive
no more emails, please click on the link below to do so.
" . BASEHREF . "unsubscribe.ph p?email=" . $email_addr . "
-------------------------------------------------------";
}
else {
$fullmessage = $message;
}
mail("$email_ad dr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}");
$sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
$res3 = mysql_query($sq l3) or die("Couldn't update SENT field.");
sleep(4);
}
echo "email sent!";
?>
obtaining email addresses and send an email to each. It is modified form
fomr some code I found on the net.
With each while loop, it updates the SENT field of the processed row to mark
it sent. I have a sleep function in there to slow the processing down to
see if that alleviated the following problem - it did help.
What is happening is the first 20 emails it sends correctly. Then it starts
sending with no $subject or $message but the remove form list text is still
in the email. When I did it for a client, some clients ending up geting 5
blank emails and one good email. It was bizarre and not uniformly wrong.
When I send it, I follow the progress in almost real time by monitoring the
test email account. When it started sending blank emails, I stop the web
form used for sending.
After I stopped it, I have about 35 emails. The database has about 1000
addresses. However, the database shows that ALL rows' sent field were
updated.
Any ideas of how to improve or rewrite this to work? Could it be that it is
on a shared server and there's something going on there?
Many thanks for your help!
<?
$subject = $_POST[subject];
$message = $_POST[message];
$sql2 = "select address from email_table";
$res2 = mysql_query($sq l2) or die("Couldn't get addresses.");
$headers = "From: \"".FROMNAME."\ " <".FROMEMAIL."> \r\n"; //from a config
file
$email['fromemail'] = "me@mydomain.co m";
$headers .="Return-Path: <me@mydomain.co m>\r\n";
while ($row = mysql_fetch_arr ay($res2)) {
$email_addr = $row[0];
if (INSERTLINK == "true") {
$fullmessage = $message . "
-------------------------------------------------------
If you would like to remove yourself from this list and receive
no more emails, please click on the link below to do so.
" . BASEHREF . "unsubscribe.ph p?email=" . $email_addr . "
-------------------------------------------------------";
}
else {
$fullmessage = $message;
}
mail("$email_ad dr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}");
$sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
$res3 = mysql_query($sq l3) or die("Couldn't update SENT field.");
sleep(4);
}
echo "email sent!";
?>
Comment