tags:

views:

383

answers:

5

Hi Is there any way i can send out about 3000+ emails from one php script request without overloading a dedicated IP... the max would be 500 per hour?

If you dont get me.. here is detailed :)

I can only send out 500 emails via the mail() function in PHP per hour via my dedicated IP, is there any way i could send out for example 3000 rows of emails pulled from an email address but stagger the mail() functions out for 500 per hour...

Thanks already!

A: 

You could sleep between the calls, or, if they're already in a database, put a field in there that says when they were sent. Then you select the ones that haven't been sent, and start from there.

gms8994
The thing is.. i want this to be totally automated? For a client...
tarnfeld
i don't think he's suggesting you "select" by hand the ones that haven't been sent. I think he meant SQL select.
ithcy
how would i "sleep between calls"
tarnfeld
run via cron, sleep(1000), etc
gms8994
A: 

I would put a field in the DB to show when the last email was sent to each user and what email it was. I would also have another DB table to show each email you sent and if it has been sent to all users yet.

User Table:
Id, UserName, Email, etc, DateTimeOfLastEmail, LastEmailId

Email Table:
Id, EmailSubject, EmailContent, DateTimeSent, SentToAll(True/False), DateTimeOfFinish
Josh Curren
The thing is.. i want this to be totally automated? For a client... this would mean the client logging in in an hour and then sending the next batch...
tarnfeld
you could use a Cron Job to check every hour if there are any emails that need to be sent and if so to send them
Josh Curren
A: 

well after doing some math you could send an email every 8.3 seconds (498/hr) but it doesn't solve the problem. I think another approach would be to use a DB, query for the 500 and have a CRON job run the script every hour.

So in the DB table you could have the script update a field after the email has been sent so the next cron job will query and get the next 500 emails that need to be sent.

Phill Pafford
I like the idea of every, say 10 seconds.... i want this to be automated for my client so i can't really setup cron-jobs in cpanel every email they want to send out?
tarnfeld
the cron job would run the PHP script every 10 minutes regardless of the email. the PHP script would query the DB to get the next email and send it out as well as update the DB table if the email was sent or not. Kinda like a flag in the table so the PHP script can run once, query for the next email to send, do some updates, maybe have a time-stamp as well and some logic to check if the email has been retried or not, etc...
Phill Pafford
+1  A: 

Create 2 tables, one for the email message and one for the list of recipients. Then create a script to be run by cron that checks if there is a new message in the message table and if so sends a batch of email to the next set of recipients. Marking each recipient after the mail is sent.

Then you create a web interface for your client to create a message and attach recipients to the message once the user marks the message as ready to go your cron job picks it up and processes it.

If there aren't any messages to be sent your cron job doesn't do anything.

Craig
Hmm this is one to consider, thanks :)
tarnfeld
A: 

Hi Thanks for all the answers! The best way i found was actually to simply sleep() between calls using the sleep() as i tested 400 mails, this took 17 seconds :)

It is unlikely the user will send more than the 450 limit ... but if they do i have an if statement before the while() ends checking if there are more than 450 rows, if so it will sleep between each... this works without fiddly databases :)

Thanks!

tarnfeld