SwiftMailer, PhpMailer, etc .: Difference between mail () and sendmail

I often read that PHP mail () -Function uses sendmail internally.

So why do Mail-Libraries, such as SwiftMailer, PhpMailer, etc., give us the opportunity to CHOOSE between mail () and sendmail ?

Isn't that the same thing?

I never heard anyone say that this is NOT the same!

Please help, because I'm really confused about this!

+5
source share
3 answers

On unix-like systems, mail() does indeed use sendmail, but this does not apply to Windows (which does not have sendmail at all, so mail() instead sent via SMTP).

The real benefits of Swiftmailer etc. lies in the fact that they provide an OOP wrapper for sending emails, so that generating your electronic content is abstracted (correctly creating MIME envelopes and correctly receiving headers can be difficult, especially when user input requires escaping), as well as abstracting the actual transport mechanism ( therefore, you can replace the SMTP or sendmail transport with a custom transport using the mail provider API without having to change all your code).

+4
source

A typical sendmail binary (for example, one of the postfix), even if called via PHP mail , opens a synchronous connection with localhost and performs a complete SMTP transaction. This may mean that it is actually slower than using SMTP directly - and in fact postfix docs recommend using SMTP for localhost instead of sendmail if you are looking for performance. In particular, you can use keepalive when sending a large number of messages using SMTP.

One trick is that you can pass an additional sendmail parameter (in particular -O DeliveryMode=b ) so that it works asynchronously, in which case it returns immediately, which makes sending mail more susceptible, but because PHP is not installed to deal with this, you lose the ability to handle errors that may occur, so this is not recommended. You can use this either by calling the sendmail binary with these parameters, or by passing it in the $additional_parameters parameter.

As a rule, on PHPMailer there is no difference between the mail and sendmail parameters, although this can be useful if you want to use the sendmail binary different from the one configured for PHP.

0
source

I am using the mail () function. But sometimes I need to send email through a non-local SMTP server. Of course, I can change the setting in php.ini, but I think it is better to use some electronic library. My choice is Swift Mailer.

0
source

Source: https://habr.com/ru/post/1240183/


All Articles