need help with code irregular working code

From: NotGiven (noname_at_nonegiven.net)
Date: 02/28/04


Date: Sat, 28 Feb 2004 09:54:56 -0500

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!";
?>



Relevant Pages

  • Re: RunCommand acCmdRecordsGoToNext
    ... Another thing that may come in handy if that doesn't is to loop through the ... The database I am utilizing this ... increasing intRecordCount on each loop. ... Dim strPassword As String ...
    (microsoft.public.access.forms)
  • need help with code irregular working code
    ... The code below is designed to loop through rows of a database query ... With each while loop, it updates the SENT field of the processed row to mark ... When I did it for a client, some clients ending up geting 5 ...
    (alt.php)
  • Re: Sql Connection
    ... ..i dont like the code either....again a example of a loop ... making calls to the database .... ... what i did yesterday is just get the parsed data to a temp table on the ... the question is the open connection where the Datareader is used insid ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: View contents of a folder
    ... For example, if your backup files are located on your D drive, in the backup ... to loop through that directory looking for other files that match the ... allows you to copy the backup file over your backend database, ... >> Folder browser and let you select a file via that mechanism. ...
    (microsoft.public.access.queries)
  • Re: How to Delete Rows in Excel In a Do Loop
    ... have to delete there are some that have a entry in each and every cell ... Richard Buttrey wrote: ... time you go through the loop. ... Now copy this formula down column A for the whole database ...
    (microsoft.public.excel.worksheet.functions)