I have a process to batch the sending of mail messages.
I use a form to input selection criteria, and other variable information, and on SUBMIT, that form calls another php file that does the mySQL query, walk through the ResultSet, sends each mail message, and aggregates success metrics which are sent at the end of the process. Also, the results are echoed to screen so the user has confirmation of execution...
To accommodate the 500 message per hour limit, I added a "sleep(8)" statement after each successful "mail()" statement.
When running this process in real time, the user's PC is "frozen" while it waits for the execution to complete, and with several hundred messages, the PC is locked for an hour or more (see code below)...
I think I may need a CRON or some other execution file that would enable a simple message to the screen ("Your job is being run..."), and release the user's PC.
I would be most appreciative of any advice on how to resolve this (I have no experience with CRON).
Thanks in advance!
JTG
Code://--- MAILER form... this is a form that //--- gets input from screen for criteria for this job //--- On SUBMIT, call Mail_Batcher_Send.php file to query DB, //--- select recipients, and send each mail message //--- Here is FORM tag that invokes Mailer scripts on SUBMIT: <form name="Mailer" method="post" action="Scripts/Mail_Batcher_Send.php"> ########[ next form ]############# //--- SEND_MAIL form (Mail_Batcher_Send.php). Invoked when previous file is submitted //--- This will query database to select a batch of records (usually 300 to 600 in resul tset) //--- Mail message is coonstructed with data from result set (code omitted here for brevity) //--- and sends each mail message ( $ResultMsg and $ErrorTrap variables retain success or failure stats //--- and send back to originator to report results of process: <?php $ErrorTrap = ""; $ResultMsg = ""; $Counter = 0 ; $Failed = 0 ; // Make a MySQL Connection mysql_connect($hostname,$username,$password) or die(mysql_error()); @mysql_select_db($database) or die( "Unable to select database" . mysql_error()); $newQuery = "SELECT * FROM Recipients ORDER BY $sortBy"; $result = mysql_query($newQuery) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $recipientAddress = $row['EmailAddress']; $RecipientName = $row['LastName'] . ", " . $row['FirstName']; $GreetingName = $row['GreetingName']; $PersMsg = $row['PersMsg']; if (mail($recipientAddress,$Subject,$msg,$headers)) { $ResultMsg .= "<tr><td nowrap>Sent to: </td><td nowrap>" . $RecipientName . "</td><td nowrap>" . $recipientAddress . "</td></tr>" . $eol; $Counter = $Counter + 1; sleep(8); //-- Pause to remain below the 500 message per hour limit } else { $ErrorTrap .= "<tr><td nowrap>NOT Sent: </td><td nowrap>" . $RecipientName . "</td><td nowrap>" . $recipientAddress . "</td></tr>" . $eol; $Failed = $Failed + 1 ; } } $ResultMsg .= $eol . $eol . $eol . "<tr><td colspan=3 bgcolor=navy height=5></td></tr>" . $eol . $ErrorTrap . $eol; $Summary = $msgHdr . $Counter . " sent<br>" . $Failed . " failed...<br><table border=0 cellspacing=0 cellpadding=0><tr><td colspan=3 bgcolor=navy height=5></td></tr><tr><td><b>Action</b></td><td><b>NAME</b></td><td><b>eMAIL</b></td></tr>" . $ResultMsg . $eol . "</table>" . $eol; //--- Send ResultMsg mail($email6,$Subject2,$Summary,$headers); //--- Echo results to screen so user knows process executed echo "<b><u>Mailer Results Summary</u></b><br>" . $eol . "Sent by: " . $FullName . "....Sent From: " . $SentFrom . "<br><br>" . $eol . $Counter . " sent<br>" . $eol . $Failed . " failed...<br>" . $eol . "--------------------<br><b><u>Failures</u></b><br><table border=0 cellspacing=0 cellpadding=0>" . $eol . $ErrorTrap . $eol . "</table>" . $eol; ?>


