ibnclaudius Posted September 26, 2011 Share Posted September 26, 2011 I made a script to send 10 emails every 30 seconds to different recipients, but sometimes it fails, stops while sending, doesn't send all... <?php include('config.php'); $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $i = 0; while ($row = mysql_fetch_array($getUser_not_sent)) { $emailUser = $row['email']; $emailFrom = "from@from.com"; $emailSubject = 'subject'; $emailVerify = "url.php?email=" . $emailUser; $emailBody = "<a href = \"$emailVerify\">link</a>"; $emailHeaders = "From:" . $emailFrom ."\r\n"; $emailHeaders .= "MIME-Version: 1.0\r\n"; $emailHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $emailHeaders .= "X-Priority: 3\r\n"; if (mail($emailUser, $emailSubject, $emailBody, $emailHeaders)) { mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'") or die (mysql_error()); $i++; } if ($i == 10) { sleep(30); $i = 0; } } exit; ?> What should I change? Link to comment https://forums.phpfreaks.com/topic/247866-email-in-mass/ Share on other sites More sharing options...
codeprada Posted September 26, 2011 Share Posted September 26, 2011 The default execution time of each script is 30 seconds. You may want to set it to 60 seconds or however long if it takes longer than 30 seconds to send 10 emails. <?php ini_set('max_execution_time', 60); ?> Link to comment https://forums.phpfreaks.com/topic/247866-email-in-mass/#findComment-1272783 Share on other sites More sharing options...
ibnclaudius Posted September 26, 2011 Author Share Posted September 26, 2011 How I would implement this: ini_set('max_execution_time', 60); on this? <?php include('config.php'); $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $i = 0; while ($row = mysql_fetch_array($getUser_not_sent)) { $emailUser = $row['email']; $emailFrom = "from@from.com"; $emailSubject = 'subject'; $emailVerify = "url.php?email=" . $emailUser; $emailBody = "<a href = \"$emailVerify\">link</a>"; $emailHeaders = "From:" . $emailFrom ."\r\n"; $emailHeaders .= "MIME-Version: 1.0\r\n"; $emailHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $emailHeaders .= "X-Priority: 3\r\n"; if (mail($emailUser, $emailSubject, $emailBody, $emailHeaders)) { mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'") or die (mysql_error()); $i++; } if ($i == 10) { sleep(30); $i = 0; } } exit; ?> Link to comment https://forums.phpfreaks.com/topic/247866-email-in-mass/#findComment-1272792 Share on other sites More sharing options...
ibnclaudius Posted September 26, 2011 Author Share Posted September 26, 2011 Is there a better way to send 10 seconds every 30 seconds, sometimes this one fails... Link to comment https://forums.phpfreaks.com/topic/247866-email-in-mass/#findComment-1273001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.