Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony and SwiftMailer sending with starttls

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?

like image 322
2latlantik Avatar asked Oct 14 '25 10:10

2latlantik


1 Answers

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.

like image 198
mattxtlm Avatar answered Oct 16 '25 22:10

mattxtlm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!