PHP - Swiftmailer using STARTTLS and self signed certificates
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.Swiftmailer has now been updated to include an option for this. It can now be solved using theBe sure you fully understand the security issues before using this as a solution.
setStreamOptions
method from your Swift_SmtpTransport
instance rather than editing the swift class.$transport = Swift_SmtpTransport::newInstance('smtp.server.com', 123, 'tls')
->setUsername('username')
->setPassword('password')
->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));
How to deal with self-signed TLS certificates in Laravel's SMTP driver?
Well in that link you provided the solution is straight-forward.
The correct solution is to fix your SSL config - it's not PHP's fault!how to fix it? in
config/mail.php
,'driver' => env('MAIL_DRIVER', 'smtp'),
should be 'driver' => env('MAIL_DRIVER', 'mail'),
(credits: Danyal Sandeelo) Shopware: Unable to connect with STARTTLS without encryption
By default, the SMTP transport in the Symfony Mailer performs TLS peer verification. You can disable this verification by setting the parameter verify_peer
to 0
, for example:
MAILER_URL="smtp://localhost:25?encryption=&auth_mode=&verify_peer=0"
Symfony swiftmailer via smtp gmail on localhost openssl error
It seems, that the problem is the self-signed certificate as you are on your local machine.
You must add the following to your config.yml (or if you prefer to separate test/dev from prod in the subsequent config_dev.yml):
swiftmailer:
# ... your other config
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
This way it should work and you have dev and prod env separated.Look also here: https://github.com/symfony/swiftmailer-bundle/tree/master/Tests/DependencyInjection/Fixtures/config/yml
Swiftmailer doesn't work
In my Gmail configuration I also need to define the swiftmailer encryption
option to ssl
.
Maybe you should add the following to your config?
parameters:
mailer_transport: smtp
mailer_host: mail.myweb.cz
mailer_port: 587
mailer_encryption: tls
mailer_user: noreply@myweb.cz
mailer_password: pass
And then in your app/config/config.yml
file add those new options too:swiftmailer:
# ...
port: %mailer_port%
encryption: %mailer_encryption%
Reference: http://symfony.com/doc/current/reference/configuration/swiftmailer.html#encryption
Related Topics
Check If Two PHP Datetime Objects Are Set to the Same Date ( Ignoring Time )
PHP Local Server Invalid Request (Unexpected Eof)
Merging Overlapping Ranges in PHP Arrays
Parsing Xml Data Using PHP to Put into MySQL Database
Magento Products by Categories
What Sort Algorithm Does PHP Use
Regex to Conditionally Replace Twitter Hashtags with Hyperlinks
Different Timezone_Types on Datetime Object
PHP Sum Variable in While Loop
How to Convert Emoji from Unicode in PHP
Why a Full Stop, "." and Not a Plus Symbol, "+", for String Concatenation in PHP
(When) Should I Use Type Hinting in PHP
Php: How to Set Current Working Directory to Be Same as Directory Executing the Script
Apache Virtual Host Not Parsing PHP
Setting Default Values (Conditional Assignment)