Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many emails can PHP send at one time?

Tags:

php

email

I have over 4,000 users who subscribed to weekly updates via email. To send an email, I simply use:

mail($to,$subject,$message,$headers);

Which works perfectly fine. My question is: how many emails can you send at once? Can I send all 4,000 at once by stepping through array of emails inside a loop? Or will that cause a time-out situation, wjere only part of the list receives emails?

like image 319
NoobDev4iPhone Avatar asked Nov 30 '11 05:11

NoobDev4iPhone


People also ask

How many emails can PHP mail send?

can send more than 10000 mail without using smtp or other mail server? No it cannot send even 1 email if you don't provide it either of them. If you don't provide an external smtp then you have to have a mail server installed on the machine itself. Once that is done, 10k mails are not a problem.

Can PHP send emails?

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );

Does PHPMailer have a limit?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *.


2 Answers

Generally, your limit is PHP's memory allocation and script timeout, both of which can be increased. A bigger limiting factor is spam firewalls, which typically limit the number of emails that can come from a server and to another domain. Bulk email services use intervals to limit the amount of mail sent to any given domain during a given time period.

like image 79
Matt H Avatar answered Sep 27 '22 20:09

Matt H


PHP has no limit, and you can do what you say and run it in a tight loop.

On linux it is sendmail, or a sendmail clone. If it starts to get overloaded it should start queueing your mails, and delivering them when it can. For Windows you have a socket connection, and I suppose the mail server might start refusing connections if it got overloaded.

Unless you are in a hurry to send them all, consider a sleep(2) between each call to mail(). If all goes smoothly then try sleep(1) the next time. Then usleep(500000) next time, etc. (UPDATE: following Matt's suggestion, put set_time_limit(10) inside the loop to avoid running out of CPU time.)

If you want them sent out even quicker you round-robin with multiple local relays. (On windows you could handle this by setting the SMTP php.ini setting; on linux you'd use on of the libraries that sends email over a socket.) Or consider a professional mail broadcasting service, where they take care of all these issues for you.

EDIT Just saw your comment about running it from your Mac. I'd assumed a server situation, with a real mail server with a global IP. If your Mac is behind a firewall you are most likely set to forward all your email to your ISPs mail server. Your ISP may well get upset about receiving 4000 emails from you in a short period of time. (E.g. they may assume your machine has been compromised by a virus and shut you down.) Also, on shared hosting, agreeing not to send out lots of email is often part of the contract. So be careful there too.

like image 31
Darren Cook Avatar answered Sep 27 '22 20:09

Darren Cook