I used to use Swift Mailer all the time as it is so easy to setup and configure but about a year ago switched to phpmailer as I had a new mail server setup with starttls that I wanted to use and whatever I did I couldn’t get it going.
Just recently been trying to improve the efficiency sending large amounts of emails which led me to revisit Swift… and remember why I stopped using it! Swift Mailer v4.0.6 does not support STARTTLS… however, we can make it do it with a few tweaks:
After a few hours of searching and experimenting I came across a patch written to add starttls support. I’d never done a ‘patch’ in Linux before but it was easy enough once pointed in the right direction.
For those unable to patch/not on Linux/can’t be bothered, I’ve packaged up a zip of Swift Mailer v4.0.6 with starttls added for download.
You use starttls in the normal way, check the example below…
$transport = Swift_SmtpTransport::newInstance('mail.example.com', 25, 'starttls') ->setUsername('username') ->setPassword('password'); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance('title', 'message', 'text/html') ->setFrom(array('email@example.com' => 'name')) ->setTo(array('firstname.lastname@example.org' => 'name')); $mailer->send($message);