954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

slow php email sending problem

i am runing this script it is fine for one contect but when i try this on 4 recepients it is not working just showing this error..
Fatal error: Maximum execution time of 30 seconds exceeded in D:\Hosting\8011955\html\admin\newsletter.php on line 60

please help me to improve this code..
Thanks i just want to send email not more than 200
here is the code

if(!(is_array($errors)))
	{

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: \"".$from_name."\" <".$from_email.">\n";

		$query="SELECT email From newsletter WHERE visible='1'";
		$result=mysql_query($query) or mysql_error();
		while($rowdata=mysql_fetch_array($result))
		{
		   $headers .= "To: \"".$to_name."\" <".$rowdata['email'].">\n";	
	           mail($rowdata['email'], "$sub",$message, $headers);
                }	
	}
xofth
Newbie Poster
18 posts since Apr 2010
Reputation Points: 8
Solved Threads: 0
 

Try the following:

if(!(is_array($errors)))
	{

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: \"".$from_name."\" <".$from_email.">\n";

		$query="SELECT email From newsletter WHERE visible='1'";
		$result=mysql_query($query) or mysql_error();
		for ($i=0;$rowdata=mysql_fetch_array($result) && $i<200;$i++)
		{
		   $headers .= "To: \"".$to_name."\" <".$rowdata['email'].">\n";	
	           mail($rowdata['email'], "$sub",$message, $headers);
                }	
	}
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

when messing up with mime it is better to use third party packages that will save you pain like PHPMailer or swiftmailer

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 
when messing up with mime it is better to use third party packages that will save you pain like PHPMailer or swiftmailer


I find it better to use the in built mail function because it uses the local mail server rather than a third party mail server. Also using the mail function can speed things up if you have configured the mail function correctly in the php.ini file along with an active mail server on the local server. :)

cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 
I find it better to use the in built mail function because it uses the local mail server rather than a third party mail server. Also using the mail function can speed things up if you have configured the mail function correctly in the php.ini file along with an active mail server on the local server. :)


I agree with you but for newbees, dealing with mime is not funny :)

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You