Image

Imageantisocial wrote in Imagephp_dev

Guide the Jedi

Ok so I've finally got my code working for taking our updates on the site and stripping out incompatible code and replacing it then BCC all the signed up users a html mail copy of the update.
That works great for right now. But I'm trying to look ahead. For when the list gets too large to send out without risking time outs. I know I should have looked at it from the first but it's a situation where it's get something working now. The problem is I'm still learning so here's my query. I've got my code shown below. I was wondering if anyone could help me figure out how to instead of pulling all the emails at once and sending the one message, I'm guessing I need to pull the users from the db one at a time some how and send each one the email until it reaches the end of the list. My thought is a setup like that should solve the time out problems?



if ($mail == "yes") {
global $setting_site_name, $setting_site_url, $setting_mail_email;
$fhandle = fopen("newstemps/mailpost.tmp", "r") or die("could not open newstemps/mailpost.tmp");
$mailpost = fread($fhandle, filesize("newstemps/mailpost.tmp"));
fclose ($fhandle);

$mailpost = $mailpost;
$mailpost = str_replace("{setting_site_name}", $setting_site_name, $mailpost);
$mailpost = str_replace("{setting_site_url}", $setting_site_url, $mailpost);
$mailpost = str_replace("{setting_mail_email}", $setting_mail_email, $mailpost);
$mailpost = str_replace("{post_poster}", $cookie_username, $mailpost);
$mailpost = str_replace("{post_headline}", stripslashes($headline), $mailpost);
$mailpost = str_replace("{post_date}", date("M d, Y", time()), $mailpost);
$mailpost = str_replace("{post_post}", stripslashes($post), $mailpost);
$mailpost = str_replace("javascript:gotoUpdate(", "", $mailpost);
$mailpost = str_replace(");", "", $mailpost);

$to = "anti@anti-blank.com";
$from = "from: " . $setting_mail_email;
$bcc = "bcc: ";
$query = mysql_query("SELECT * FROM members");
while ($member = mysql_fetch_array($query)) {
if ($bcc == "") {$bcc = $member['email'];}
else {$bcc .= ", " . $member['email'];}
}
$headers = $from . "\r\n" . $bcc . "\r\n" . "Content-Type: text/html; charset=iso-8859-1\n" ;
mail ($to, $setting_site_name, $mailpost, $headers) or $emailsuccess = "Failure sending email.";
if ($emailsuccess == "") {$emailsuccess = "Email Sent Successfully.";}
}



Any ideas? Or even pointing me where is a good place to look, not looking for handouts (though those are nice) just looking for someone's wisdom *smile* Thanks.