note 60808 added to function.mail

From: Date: Tue, 17 Jan 2006 13:02:31 +0000
Subject: note 60808 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-101963@lists.php.net to get a copy of this message
If you must send e-mail to multiple addresses stored in your database using a loop, and you do not have access to the PEAR packages mentioned above, then a simple fix would be to use the sleep() function to put some time in between each call to the mail() function. For example: $emailQuery = "SELECT EMail FROM Customers WHERE OptIn='1'"; $result = mysql_query($emailQuery) or die ("Query Failed: ".mysql_error()); $rec = mysql_fetch_array($result); while($rec) { //Allow up to 10 attempts to send a message $retries = 10; while ($retries > 0) { if(mail($rec['EMail'], $mailingRec['Subject'],$htmlText,$headers)) { //A simple counter used to check success rate $messagesSent++; break; } $retries--; //1 second delay per retry; sleep(1); } $rec = mysql_fetch_array($result); } This may take some time to complete depending on the size of your mailing list. ---- Server IP: 64.71.164.2Probable Submitter: 67.163.73.205 ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60808 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60808&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60808&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101963) next »