while() sending email times out...
Moderator: General Moderators
while() sending email times out...
I'm having a problem with a newsletter script I wrote. I used a while loop to send the email out to all users in the database and when executing, it returns an error after sending about 50 email. There are over 600 email in the DB. The script I wrote has worked before without any issues, but I've never had more that 50 members to send to.
Is there a limit when using the mail() function? If so, how do I get around it. I do not have access to the server's config files.
Is there a limit when using the mail() function? If so, how do I get around it. I do not have access to the server's config files.
-
loiclavoie
- Forum Newbie
- Posts: 2
- Joined: Mon Sep 27, 2010 1:14 pm
Re: while() sending email times out...
What's the error you get?
-
jabbaonthedais
- Forum Contributor
- Posts: 127
- Joined: Wed Aug 18, 2004 12:08 pm
Re: while() sending email times out...
We would need to see the error to really know what's going on. It's possible something on the server is stopping your mail function from running too frequently by design. Many hosts put limits in place to prevent spam. You could setup a quick cron job (or just run a script manually) to send all the mails out in batches. Add a field to your database to mark if that e-mail address has been mailed, then have your script grab 50 (or less) addresses than have not been used, send the mails, and mark them good. If your script is updating the table each loop, you won't have to worry about an error breaking the batch and not knowing where it stopped.
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: while() sending email times out...
Contact your hosting provider and discribe your problem.
Re: while() sending email times out...
thought about adding the sent verification to the db, but I'd have to clear it each time I sent the newsletter. And as for running the script again, I'd have to send it out to all the customers again and I'd rather not spam everyone.
guess I could just change the MySQL query to ORDER DESC and try it again since it will probably crash again before it gets to the rows it already sent to.
I'll try that and see if I get the error again.
guess I could just change the MySQL query to ORDER DESC and try it again since it will probably crash again before it gets to the rows it already sent to.
I'll try that and see if I get the error again.
Re: while() sending email times out...
OK...just set the db to update the current newsletter's date so I don't have to reset anything.
Here's the error message I get:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log."
I would have contacted the admin first, but it's through GoDaddy and I haven't had much luck with their support staff in the past.
Checking the DB, it did manage to send out to 181 of the 587 rows, but that's still leaving 506 people not getting the newsletter and these customers can be rather...irritable? (I work for a casino and the custumers want their coupons!!! lol)
I've read in some other newsletter scripts that some servers limit messages being sent out to like 50 or whatever...there a way around that? I could manually batch them, but I'm trying to set this up for my client to run as smootly as possible.
Thanks!!!
Here's the error message I get:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log."
I would have contacted the admin first, but it's through GoDaddy and I haven't had much luck with their support staff in the past.
Checking the DB, it did manage to send out to 181 of the 587 rows, but that's still leaving 506 people not getting the newsletter and these customers can be rather...irritable? (I work for a casino and the custumers want their coupons!!! lol)
I've read in some other newsletter scripts that some servers limit messages being sent out to like 50 or whatever...there a way around that? I could manually batch them, but I'm trying to set this up for my client to run as smootly as possible.
Thanks!!!
Re: while() sending email times out...
just ran phpinfo() and seen that the max execution time is set to 30 seconds which is about how long it runs before I get the error. So I'm just going to have to set it up to run x amount at a time.
time to hit the books to figure that one out! lol
time to hit the books to figure that one out! lol
Re: while() sending email times out...
As already mentioned, send them out in batches. You will not be spamming people, as each time a section runs, you should only be selecting valid e-mails that are not already marked as sent.
Also, instead of a cron job, as long as you will have the window open, have the processing page give out a META refresh to refresh the page every minute or so (give it time to wait a little bit between 30 seconds of processing), The page will read in say 50 addresses, as it sends each one, it will update the database to indicate they already received it (or at least tried).
As for the having to clear that every time you send a newsletter, that is a simple SQL something like UPDATE Subscribers SET EmailSent='N';
For business use, if you are not well experienced in setting this up, you may want to look to a 3rd party system, The plus sides include 1) they have servers set up for this, 2) they have less chance of getting the sending e-mail flagged as a spammer and possibly blacklisted 3) they are usually up to date on the legalities in doing such mailings, as that is their business. They will most likely know and already have in place systems to handle people requesting being removed and such.
-Greg
Also, instead of a cron job, as long as you will have the window open, have the processing page give out a META refresh to refresh the page every minute or so (give it time to wait a little bit between 30 seconds of processing), The page will read in say 50 addresses, as it sends each one, it will update the database to indicate they already received it (or at least tried).
As for the having to clear that every time you send a newsletter, that is a simple SQL something like UPDATE Subscribers SET EmailSent='N';
For business use, if you are not well experienced in setting this up, you may want to look to a 3rd party system, The plus sides include 1) they have servers set up for this, 2) they have less chance of getting the sending e-mail flagged as a spammer and possibly blacklisted 3) they are usually up to date on the legalities in doing such mailings, as that is their business. They will most likely know and already have in place systems to handle people requesting being removed and such.
-Greg
Re: while() sending email times out...
never thought of the refresh option! that's a good idea...thanks.
As for 3rd party apps, I kind of want to keep this all within the site and trying to make it as simple to use as possible and with one login. Most external scripts I've run across have their own login and that can get kind of annoying.
As for 3rd party apps, I kind of want to keep this all within the site and trying to make it as simple to use as possible and with one login. Most external scripts I've run across have their own login and that can get kind of annoying.