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);
                }	
	}

Recommended Answers

All 4 Replies

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);
                }	
	}

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

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. :)

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 :)

commented: agreed :) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.