PHP: mail() vs SendMail

2019-06-15 08:35发布

问题:

a simple question: which one has good performance for sending mails in bulk?

mail() function or sendmail

which one is used by popular PHP list manager packages?

回答1:

Well the mail() function is not really suitable for emails sent in bulk because it opens and closes an SMTP socket for each email you send, which is far from being efficient. If you look at PEAR::Mail it allows you to use 3 backends: mail, sendmail and plain SMTP. For what it's worth, I've personally preferred SMTP because it's easy to support on both Linux and Windows.

If you wish to send mails in the background using a queue, PEAR::Mail_Queue might be a solution.



回答2:

sendmail is a Mail Transfer Agent (MTA). On UNIX and Linux based systems, PHP's mail() function simply relays the email though sendmail (or a compatible MTA). For sending bulk email, you may want to look into directly connecting to an SMTP server. Zend Framework provides an SMTP transport.



回答3:

If you are running the SMTP mail server yourself, make sure you have SPF and domain keys set up properly or your mail will end up in the junk box for most large domains (yahoo, gmail etc).

Also don't forget about bounce handling and robust unsubscribe functionality. Without those your email blasts will be much less effective, and your IP will get blacklisted.

And of course don't allow open relays. Do your homework and tread with caution, spammers have made it difficult for us.