Hi guys, Is it faster to use a while loop to send email: ($addresses is an array with email addresses in it) foreach($addresses as $to) { mail($to,'test','this is a test msg','From:someone@example.com'); } Or to run mail() once, with $to being a list of addresses written like ? Thanks, -Tony
Okay, I'll take your word for it... But why? I'd just like to know for future reference. Thanks, -Tony
Just because CCing all the emails will make one request to the outside network and using mail() will make a request for each email address, but if you have a large number of emails then I wouldn't recommend CCing them.
What do you mean by a large number? And if I did have a large number, what would you recommend? Thanks, -Tony
For me anything over 100 is large for a single email, and if you are sending over 1500 mails in one day then I would recommend you to check mail sending services like sendgrid.com and use their API to send emails.
Okay. Because my site is not popular now, and is down as well, I will just use my server's sending capabilities. Thanks.
Yep as long as you are below 1500-2500 emails/day it is better to use your server's sending capabilities .
An addition of what Arsalan said, it is faster to use bulk CC (I would use BCC instead so users do not see the other user emails) if you are using php built in mail(). If you are using PEAR Mail (or any other famous email systems that share SMTP connections), then this is not an issue and then it is favored to send it individually if you want to know the results of the email (was it actually sent to the recipient or if it failed). Using PHP built in mail() makes an SMTP request each time it is called, which can slow things down. PEAR mail on the other hand is faster: http://pear.php.net/package/Mail You can also use other libraries. In regards to the limit of BCC/CC you can send, it does not matter. Whichever email system you use will send the message to each account independently. It all depends on your host's maxrecipients email config. If it is more, it will fail.
Master, I beg to differ with you on one point!!!!!!!!!! Even though there might not be any limit from your host or PHP, but if you are frequently sending emails with a large number of addresses as BCC or CC then it is very likely that you will be marked as spam by most of the email service providers, so to be on the safe side I would recommend to limit the number of CCs and BCCs.
NO CC PLEASE! BCC is 100% better! And for sending emails, just use the mail function in PHP and send each email seperate! this way you 100% know that others don't see email addresses from other users.
Hey Arsalan, Emails send via mail will not be marked as spam no matter how many you send (I always used it on high traffic sites with no issues), unless you incorrectly set the headers or do not have your reverse DNS setup properly. You can also make sure the user you are sending the mail() from is part of Sendmail allowed users.