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);

5 Responses to Swift Mailer with STARTTLS

  1. 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.

  2. No problem! Glad I could help :)

    For info, I heard the next big-ish release of Swift Mailer should include STARTTLS support.

  3. Shalom Levytam says:

    It seems the download link is broken. Could you please update it?

  4. Hi, sorry for the really late reply. My counter had broken, download should work again now.

    Richard

  5. [...] of a chore (probably went about it the wrong way), so have zipped it up ready for download here: Swift Mailer with STARTTLS [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">