merylvingien Posted December 1, 2009 Share Posted December 1, 2009 Hi fellas, i am trying to build a page so that i can email all the users of my site. Sort of a mass mail page. Trouble is when i test this on my local machine, the code works ok, and starts trying to send the emails (although i havent setup a mailer on my localhost) But for some reason it stops and gives me this: Fatal error: Maximum execution time of 60 seconds exceeded I am only trying to send 70 or so emails. Ive actually used some code that i foud on here and just changed it a bit: $con = mysql_connect("localhost", "root", ""); if (!$con) { die('error'); } $db_selected = mysql_select_db("table",$con); $message= $_POST['message']; $from = "[email protected]"; $sql = mysql_query("SELECT email FROM table"); while($line = mysql_fetch_assoc($sql)){ $email[] = $line; } foreach($email as $e){ //Remove whitespace in case there is some. $e['email'] = trim($e['email']); mail($e['email'],"Wasp Control UK",$message,"From: $from"); echo "Message sent to {$e['email']}"; usleep(500000); } Anyone know why this would time out? Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/ Share on other sites More sharing options...
aeroswat Posted December 1, 2009 Share Posted December 1, 2009 Have you tried removing the usleep? Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969041 Share on other sites More sharing options...
merylvingien Posted December 1, 2009 Author Share Posted December 1, 2009 I have, makes no difference! Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969049 Share on other sites More sharing options...
mrMarcus Posted December 1, 2009 Share Posted December 1, 2009 not sure where you're getting this from: $e['email'] $e does not contain an index of 'email'. within your foreach() loop, just use $e, and get rid of $e['email']. and try sending one email first, make sure that works, and then move onto more. Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969055 Share on other sites More sharing options...
mattal999 Posted December 1, 2009 Share Posted December 1, 2009 You need to add: set_time_limit(600); ignore_user_abort(1); set_time_limit(seconds) sets how long the script is allowed to run for without stopping. ignore_user_abort(1) sets that the script should not stop parsing if the user closes their browser window. Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969059 Share on other sites More sharing options...
merylvingien Posted December 1, 2009 Author Share Posted December 1, 2009 I tried removing the ['email'] part and get an error: Warning: trim() expects parameter 1 to be string, array given in on line 23 Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969062 Share on other sites More sharing options...
merylvingien Posted December 1, 2009 Author Share Posted December 1, 2009 You need to add: set_time_limit(600); ignore_user_abort(1); set_time_limit(seconds) sets how long the script is allowed to run for without stopping. ignore_user_abort(1) sets that the script should not stop parsing if the user closes their browser window. That done the trick Link to comment https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.