What mail () function can I use for 30 seconds?

I need to make a page that will send email to newsletter subscribers. Over 14,000 subscribers. I want to use the php mail () function to send them email. But I'm afraid that he will not be able to send email to all subscribers for the max_execution_time php 30sec restriction. It is not possible to verify how much email can be sent by sending a test email to subscribers. Therefore, I want to know how much email can be sent with the mail () function within 30 seconds of max_execution_time. It will be very helpful if you can answer me.

also another question: mysql runtime is also calculated in php?

Apache Version 2.2.13 (Unix) PHP Version 5.2.11

+4
source share
5 answers

The php max_execution_time setting is configurable. 30 seconds is the default value, but you can set it to 0 seconds without limiting the execution time. Use set_time_limit () .

 set_time_limit(0); 

If you do this, you can send all your email.

Please be careful when sending multiple letters to the same mail server per second. You do not want to be blacklisted.

+4
source

You must run this from a cronjob or create a background job or use something even more suitable for batch jobs.

You can receive 14,000 emails in 30 seconds if your mail server is fast enough, but what happens when you get a few more subscribers and stop working properly?

Perhaps you can set a flag in the database for each user, then reset the flag, because their email address is sent by the background job. This will help to avoid duplicates, etc., if there is a problem with the mail server.

+3
source

It depends on so many variables that one answer is impossible. Factors include:

  • Processor speed
  • Bandwidth available from the sending system to the MTA
  • MTA features for receiving emails

The only way to find out is to try.

+2
source

I had this exact problem some time ago in one of my projects. The solution is to isolate the sending of email from the actual site.

I have encoded a small class that will be called to send an email. It will be transmitted by the email template, which will then be stored in the database in the mail queue. At the back end, I had a cron job called a mail script every X seconds. The script looks at the database queue for email, grabs the X number from the queue to try to send (sorted by timestamp), and then tried to deliver. Assuming the errors were not reset, the script will mark the message as sent. The next step is to clear all emails from the queue sent and older than X days (for journaling).

Hope this helps.

0
source

Seriously, if you want to send the same mail to ten people from a regular mail client, do you usually create ten identical letters or just send mail after adding recipients to the mailing list?

Edit: If the answer is β€œI send it once”, I think you should also look in that direction (even described how to send to multiple recipients at http://www.php.net/mail )

-4
source

All Articles