tarlejh Posted December 16, 2007 Share Posted December 16, 2007 I have a script that I use to generate and send out invoices for a customer database. It is a simple script: for an array of email addresses in a $_POST array, $sentok=mail() and then, if ($sentok) { echo 'Mail sent OK.'; } else { echo 'Mail not sent.'; } As you can see, a FOR loop outputs an HTML log of which emails were successful. The script works great for a few at a time, but when I kick it up to oh, say 700 iterations, it starts back bringing back mixed results, with email being sent about every other iteration. I know it's not an issue with the email address being invalid, so what could cause mail() to be failing? Could there be a limitation with my host (godaddy) that only allows the server to send a certain number of emails per second? One idea I thought of is to try telling PHP to sleep() during the loop...but thats just a wild guess. Any ideas on what the problem is, or how I should rewrite the script? Quote Link to comment Share on other sites More sharing options...
corbin Posted December 16, 2007 Share Posted December 16, 2007 Everytime you call mail() a new socket is opened, so you're better off using something else for large iterations. That may or may not be the problem, but I suspect it could be part of it. If you take one of the failed emails and do it seperately, does it work? Quote Link to comment Share on other sites More sharing options...
tarlejh Posted December 16, 2007 Author Share Posted December 16, 2007 If you take one of the failed emails and do it seperately, does it work? Yes, the failed emails go through when I do them one at a time, it only starts hiccuping when I try and send hundreds at once. Quote Link to comment Share on other sites More sharing options...
CMC Posted December 16, 2007 Share Posted December 16, 2007 The problem is most likely the number of emails trying to be sent. As corbin said, it will open a new socket everytime thus increasing server load and affecting performance. Your best to find/write an alternative script, perhaps one that communicates directly with an SMTP server. Below is a link for a free PHP mailer. I haven't tried it out but I've seen a few people talk about it. http://www.swiftmailer.org/ Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2007 Share Posted December 17, 2007 Could there be a limitation with my host (godaddy) that only allows the server to send a certain number of emails per second? Yes there is. If you are sending through a mail box on one of their email servers, I believe the limit is 250 emails per day (unless you purchase more in blocks of 50.) In any case you should contact godaddy's support to find out for sure. Edit: The limit is also a function of the type of server - shared, VPS, dedicated... Quote Link to comment 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.