Swift Mailer with STARTTLS
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('from@example.com' => 'name'))
->setTo(array('to@example.com' => 'name'));
$mailer->send($message);
This is so usefull! Many thanks. My host had problem with connecting using SSL so I was stuck with START/TLS and this modification came from heaven. Works like charm.
No problem! Glad I could help :)
For info, I heard the next big-ish release of Swift Mailer should include STARTTLS support.
It seems the download link is broken. Could you please update it?
Hi, sorry for the really late reply. My counter had broken, download should work again now.
Richard
[…] of a chore (probably went about it the wrong way), so have zipped it up ready for download here: Swift Mailer with STARTTLS […]