Hi, I need some help with coding with mail(). I have an sql database with 3000 records, emails of users that have signed up for my newsletter. Due to restrictions imposed by my host provider, I cannot send one message to more than 30 records, thus I have a major problem with managing my newsletter. So, what I need help with is a script that divides the 3000 records by 30, than send 100 messages delayed by 30 seconds let's say. Help would be highly appreciated. Thank you.
Why not send email through a 3rd party SMTP provider? Something like sendgrid.net. It sounds like you're on a shared hosting environment, and they're generally not too good when it comes to mail delivery (because other people on the server often abuse it, and the server can get blacklisted).
you can use cron job to complete this task. Make a cron that run after a time interval ( you can set it) and sends the message to the next 30 record each time.
Assuming your doing it in a while statement I would use the sleep command. ie: while($row1 = mysql_fetch_array($r1)) { ////send an email to this user sleep('30'); } Now it wouldn't work the exact way you would want but this would work. Not sure what the limit is with your provider but you may need to increase that number to make it work. You could also use a count var to keep track $counter = 0; while($row1 = mysql_fetch_array($r1)) { ++$counter; ////send an email to this user if($counter == '100') {sleep('30');unset($counter);} } I would highly recommend you use a table to track the emails sent, in the event the script stops too soon. That way you don't send the email twice to the same person.
Get access to a real mail server and connect and send via SMTP like someone else suggested. There are also services that will send your mail from various IP addresses etc. which increases the chances of being delivered. Local mail programs on shared servers suck.
I don't think that's your coding problem, it seems the capacity of sending mass email of your server... So find a really mass email sending server(google for it). Or you can use sleep function to send email.... p/s: but wait.... 30s? Maybe you need to add at the head of your php code. Try it!
I second Alex's suggestion, using SMTP is the best option. I really got tired from email getting send to SPAM - which occurs most of the time if you use mail() function. Google SMTP is easy to use with almost all MVC's and always delivers for me.
@fastestsms - have gotten a LOT of errors trying to use that. Working on an autoresponder script now that was troubled by that usage, and when I switched to ini_get('max_execution_time'); PHP: the problem abruptly vanished for me. Have used this without fail multiple times