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:
If you need 100% compatible solution, you need to check
php.ini
settings and OS platform http://php.net/manual/en/mail.configuration.phpFor unix platform will be enough to call
->setCommand
withini_get("sendmail_path")
value. For windows platform support need to checksmtp
option.