I have an opt in mailing list script that sends to approximately 1,300 users. When trying to send, I often get a web site not responding or timeout error. Any suggestions?
I have php 4 and connect to a mysql database to get the email addresses.
There is a bit of code that I don't have listed here, but it's just some HTML added to the beginning and end of the emails.
This is where I call the emailer function.
if(($email == 1))
{
$emailQuery = mysql_query("SELECT email FROM `users` WHERE validated=1 AND HTML=1");
echo "Emailed to ";
echo Emailer($emailQuery,$subject,$emailbodyh, 1);
echo " HTML users<br>";
$emailQuery = mysql_query("SELECT email FROM `users` WHERE validated=1 AND HTML='0'");
echo "Emailed to ";
echo Emailer($emailQuery,$subject,$emailbodyt, 0);
echo " text users<br><p>";
echo "Successfully emailed to subscribers";
}
This is the emailer function.
<?php
function Emailer($emailQuery,$subject,$body, $type)
{
set_time_limit(1200);
$x = 1;
$emailed = 0;
$hold = 60; // quantity of emails sent before 3 sec delay
while ($sendemail = mysql_fetch_array($emailQuery)) {
$email = $sendemail["email"];
if($type == 1)
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Shankweilers movie Updates <movieupdates@shankweilers.com>\r\n";
$message = "<html><head><link rel=stylesheet type=text/css href=http://www.shankweilers.com/schedule.css></head><body>
<table width=505 border=0 cellspacing=0 cellpadding=0 class=schedule>
<tr>
<td class=movietime><img src=http://members.aol.com/mjordn12/email.jpg><img src=http://members.aol.com/mjordn12/email2.gif></td>
<td width=200 class=movietime><img src=http://members.aol.com/mjordn12/spacer.gif width=100></td>
</tr>
<tr><td colspan=2 class=text2><br><Br>
";
$message .= $body;
$message .= "</td></tr>
<tr><td colspan=2 class=movietime><BR>Subscription Info</td></tr>
<tr><td class=text2 colspan=2> To unsubscribe, visit <a href=http://www.shankweilers.com/updates/unsubscribe.php?leave=$email>[url]http://www.shankweilers.com/updates/unsubscribe.php?leave=[/url]$email</a> <br>For more info, <a href=http://www.shankweilers.com/updates/subscribe.php>click here</a> </td></tr>
</table><br></body></html>";
}
elseif($type == 0)
{
$headers = "From: Shankweilers movie Updates <movieupdates@shankweilers.com>\r\n";
$message = "
-------------------------------------------------------------
SHANKWEILER'S DRIVE-IN EMAIL LIST
Movie Updates
-------------------------------------------------------------\n\n
";
$message .= $body;
$message .= "\n\n
----------------------------------------
SUBSCRIPTION INFO
----------------------------------------
To unsubscribe, visit
[url]http://www.shankweilers.com/updates/unsubscribe.php?leave=[/url]$email\n
For subscription info, visit
[url]http://www.shankweilers.com/updates/subscribe.php[/url] \n
";
}
mail($email, $subject, $message, $headers);
$x++;
$emailed++;
if($x == $hold)
{
sleep(4);
flush();
$x = 0;
}
}
return $emailed;
}
?>
Also, it's a custom script to update the user's web site and do the emailing, so I really want to stick with what I have, maybe just improve the code some. Thanks.
I've tried changing around sleep function and such, but to no avail. I'm not sure where it's going wrong.