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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With