Encrypted SMTP

You can use SSL or TLS encryption with the SMTP Transport by specifying it as a parameter or with a method call.

To use encryption with the SMTP Transport:

  • Pass the encryption setting as a third parameter to Swift_SmtpTransport::newInstance(); or
  • Call the setEncryption() method on the Transport.

A connection to the SMTP server will be established upon the first call to send() or batchSend(). The connection will be initiated with the correct encryption settings.

Note: For SSL or TLS encryption to work your PHP installation must have appropriate OpenSSL transports wrappers. You can check if "tls" and/or "ssl" are present in your PHP installation by using the PHP function stream_get_transports()
<?php

require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 587, 'ssl');

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

/*
It's also possible to use multiple method calls

$transport = Swift_SmtpTransport::newInstance()
  ->setHost('smtp.example.org')
  ->setPort(587)
  ->setEncryption('ssl')
  ;
*/

NOTE: Documentation for version 3 is in the wiki.