471,337 Members | 1,134 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

need help with code irregular working code

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($sql2) or die("Couldn't get addresses.");
$headers = "From: \"".FROMNAME."\" <".FROMEMAIL.">\r\n"; //from a config
file
$email['fromemail'] = "me@mydomain.com";
$headers .="Return-Path: <me@mydomain.com>\r\n";
while ($row = mysql_fetch_array($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.php?email=" . $email_addr . "
-------------------------------------------------------";
}
else {
$fullmessage = $message;
}
mail("$email_addr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}");
$sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
$res3 = mysql_query($sql3) or die("Couldn't update SENT field.");
sleep(4);
}
echo "email sent!";
?>
Jul 17 '05 #1
3 1675
I noticed that Message-ID: <aU*****************@bignews3.bellsouth.net>
from NotGiven contained the following:
mail("$email_addr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}");
$sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
$res3 = mysql_query($sql3) or die("Couldn't update SENT field.");


You are updating the database, whether mail() is successful or not.
Since mail() returns TRUE if the mail was successfully accepted for
delivery, you might be better off trying
if(mail("$email_addr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}")){
//update database
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
That didn't work either - thanks though

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:7i********************************@4ax.com...
I noticed that Message-ID: <aU*****************@bignews3.bellsouth.net>
from NotGiven contained the following:
mail("$email_addr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}");
$sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
$res3 = mysql_query($sql3) or die("Couldn't update SENT field.");


You are updating the database, whether mail() is successful or not.
Since mail() returns TRUE if the mail was successfully accepted for
delivery, you might be better off trying
if(mail("$email_addr", "$subject", $fullmessage, $headers, "-f
{$email[fromemail]}")){
//update database
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #3
In article <aU*****************@bignews3.bellsouth.net>,
"NotGiven" <no****@nonegiven.net> wrote:
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.


Did you check your sendmail log (provided you use linux)? It might give you
some hints on what's happening.

--
Sandman[.net]
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by slava.shklyar | last post: by
13 posts views Thread by Rob Corwin | last post: by
7 posts views Thread by Manfred | last post: by
reply views Thread by dr | last post: by
4 posts views Thread by shihaoran | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.