I'm using the SwiftMailer class to send mail using the php mail() function or SMTP depending on my app's configuration (development or production). My code looks like this :
// Default mailer: php mail() function
$this->transport = \Swift_MailTransport::newInstance();
// If a SMTP host is defined
if (isset($_SITE['site_smtp_host'])) {
$this->transport = \Swift_SmtpTransport::newInstance($_SITE["site_smtp_host"], 587)
->setUsername($_SITE["site_smtp_user"])
->setPassword($_SITE["site_smtp_pass"]);
}
Since SwiftMailer 5.4.5 I'm getting this deprecation notice :
Exception: UNKNOWN ERROR (16384): The Swift_Transport_MailTransport class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.
Should I use Swift_SendmailTransport
as I was using Swift_MailTransport
? Will it work it the same environnements ? Does it also use the php mail() functions ? If not, is it not possible to use the php mail() function with SwiftMailer anymore ?
First of all, about deprecation from swift mailer site:
It is advised that users do not use this transport if at all possible since a number of plugin features cannot be used in conjunction with this transport due to the internal interface in PHP itself.
The level of error reporting with this transport is incredibly weak, again due to limitations of PHP's internal mail() function. You'll get an all-or-nothing result from sending.
If you need 100% compatible solution, you need to check php.ini
settings and OS platform http://php.net/manual/en/mail.configuration.php
For unix platform will be enough to call ->setCommand
with ini_get("sendmail_path")
value. For windows platform support need to check smtp
option.