Re: Best way to mass mail
| From: | Miles Thompson | Date: | Mon, 12 Sep 2005 14:15:57 +0000 |
| Subject: | Re: Best way to mass mail | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222186@lists.php.net to get a copy of this message | ||
At 10:50 AM 9/12/2005, Ryan A wrote:
Hi, My client has a dating site and now he wants to mail all his members, he does not want to use any of the already installed mailing lists but wants us to make one for him, he's on a dedicated server. Presently he does not have too many members, just a few thousand (around 3k i guess), I remember reading sometime back on the list that using the mail() may not be the best option...not sure if thats still true. The thing that bothers me the most is if the program times out..., how do I start again from the ones that have not been sent? eg: (10 members) mail gets sent to first 4 members then times out we re-click on the send button and it starts again from one...again times out (this happens 5 times) that means members 1-4 will get the same email 5 times Doing this the hard way would be to connect to the db after each successful mail and "mark" each member with todays date or something...but I would like to avoid so many calls to the DB if possible...esp if the site grows. Ideas/suggestions? Thanks in advance, RyanWe send to 1,000 subscribers each night, here's the guts of the code. There's one call to fetch the names and email addresses from the database.
while( $row = mysql_fetch_array( $result ) )
{
$first_name = $row[ first_name ];
$last_name = $row[ last_name ];
$email = $row[ email ];
/* recipient */
$recipient = $email;
/* send it */
$lMailedOK = mail($recipient, $subject, $message, $headers);
if ($lMailedOK != 0 )
{
$lMailedOK = "OK";
}else{
$lMailedOK="<b>FAILED</b>";
}
echo $recipient . " - " . $lMailedOK ."<br>";
// give ourselves more time
set_time_limit( 20 );
} //$row = mysql_fetch_array( $result )
$message is built higher up in the process - I keep resetting the time out - set_time_limit(20).
After each message is sent, $lMailedOK and the names are echoed to the browser.
When the process completes, we know who it went to and if the call to mail() succeeded.
Hope this is helpful - Miles Thompson