4

Can someone explain to me how work SSL AND STARTTLS with PHP ?

Il have a dedicated server with Postfix and Dovecot (managed by plesk). I don't have SSL.

To get and send my emails, I use SMTP/IMAP with STARTTLS.

But in PHP, with Swiftmailer and Symfony, I only have two options : ssl or tls. None of the 2 work in my case, emails do not leave.

Searching on stackoverflow, I put this in my code and this working :

$transport = \Swift_SmtpTransport::newInstance('smtp.server.fr', 587, 'tls')
->setUsername($username)
->setPassword($password)
->setStreamOptions(array('ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
 )));

$mailer = \Swift_Mailer::newInstance($transport);

Do you think my configuration is correct?

2latlantik
  • 77
  • 2
  • 9
  • I think it's correct, try to export you config in Ressource and parse them with YamlParser. @see the difference between START TLS AND SSL / TLS here : http://stackoverflow.com/questions/5540374/starttls-vs-ssl-tls – Weenesta - Mathieu Dormeval Dec 07 '16 at 15:14

1 Answers1

2

The port 587 you provided indicates, that the option tls is correct. So to get it working in Symfony with Swiftmailer, you don't need to instantiate a new SmtpTransport.

Simply add the following to your Swiftmailer Configuration config.yml:

Swiftmailer
    # here are some other swiftmailer options like host, user etc.
    stream-options:
        ssl:
            allow_self_signed : true
            verify_peer: false

Continue using swiftmailer as normal.

mattxtlm
  • 128
  • 9