Jump to content

Confused with mail() failures


tarlejh

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.