问题
I have to send mails to all users in the site when a new user joins. My problem is the script stops execution after sending around 400 mails. I have set the set_time_limit to 0. And also I am giving sleep(2) after sending 10 mails.
What may be the reason behind this issue.Any solution for this problem . Is there any better method to send bulk emails?
Thanks in Advance
Rose
回答1:
The way we do it is with the help of cron.
We (at our company) split up the userlist in blocks of 50 addresses. These blocks are put in a table in the database (with data that links this block to the e-mail data (headers, body, ..).
Through a cron.php file, which is triggered every 5 minutes or so, the system grabs the first available block in the database that needs to be sent and sends out the emails.
回答2:
I had a similar issue and it was down to memory usage, how are you sending them, can you provide any code?
回答3:
If PHP is running in safe mode, set_time_limit
will have no effect. If you must run PHP in safe mode, you can modify the default time limit using the configuration directive max_execution_time
.
回答4:
I don't know why your script stops. But you also asked for better ways to send bulk emails. I found that using an email package gives you much more control than the built-in PHP mail command. Swift Mailer is a very good one.
回答5:
Try setting up a task queue. When your web application wants to send an email, it adds it to a database of tasks and a separate daemon processes each one. This means, you can set an email to be sent to every member of the website and your daemon will send each one every 2-4 seconds. See the Kohana task queue module (PHP), Delayed_job (Ruby), and Celery (Python) for some inspiration.
回答6:
I'm posting a new answer because this one doesn't relate to my previous one.
I was wondering: where exactly do you set set_time_limit
to 0
? I mean, is it in php.ini, .htaccess, or from a php file with ini_set().
Is it possible that this value gets overridden?
来源:https://stackoverflow.com/questions/2938037/sending-bulk-emails-using-php