Anon-e-mouse Posted March 11, 2012 Share Posted March 11, 2012 Evening, In simple, I have a script that loops through members when submitted and sends them a confirmation email for an event. However I don't want to send 200 emails one after the other because Google would get very upset. Thus! I attempted to use sleep() but that didn't function as I thought it would inside the loop. Causing the entire thing to wait for the amount of seconds times the result set. So. Whats would you suggest? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/258693-loop-delay/ Share on other sites More sharing options...
xyph Posted March 11, 2012 Share Posted March 11, 2012 Make sure your host/ISP knows you plan on doing this, and that the emails are solicited. Your host may even have something pre-installed to help you with this. I'd approach this with CRON. Have a database table called `emails` or something, using a unique ID. Store the email's body in there. Create another table called `email_que` or something. Store the user's ID (to link back to their email) and the email's ID. You'd then create a PHP script that CRON would call every 30mins/hour/whatever. This script would grab the oldest 50/100/500/etc. rows in `email_que` and perform the mail function, removing the rows after completion. Quote Link to comment https://forums.phpfreaks.com/topic/258693-loop-delay/#findComment-1326176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.