I'm trying to configure swiftmailer in the advanced yii 2.0 template. I've gone through many posts and I understand that there are some issues with gmail. My configuration environment in development is the following:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => gethostbyname('smtp.gmail.com'),
'username' => '[email protected]',
'password' => 'xxssxxxx',
'port' => '465',
'encryption' => 'ssl'
]
I've also set the support mail that's used in the controller to the same gmail address in the main-local config shown above. I've tried switching to a less secure configuration for apps in the gmail account and it did not work and I'm not particularly fond on changing this. I get the following error when I use ssl encryption
connection could not be established with host ... [ #0]
If I don't specify the encryption I get a time out error.
I have OpenSSL support enabled according to my phpinfo file but I cannot make it work. TLS does not work either because if I change the config (port:'587' & encryption='tls') I get the following error
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Any ideas on how can I fix this? Is this an unfixed issue? Should I use another mailing extension?
For gmail: encryption must be setted to
tls
, port to587
and host tosmtp.gmail.com
(check if your gethostbyname('smtp.gmail.com'), get the correct value) see the sample below: