Jump to content

Loop Delay


Anon-e-mouse

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/258693-loop-delay/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/258693-loop-delay/#findComment-1326176
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.