I was sending emails using gmail and everything was working perfectly, but suddendly it stoped working. And it shows me this
ErrorException in StreamBuffer.php line 94:
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
in StreamBuffer.php line 94
at HandleExceptions->handleError('2', 'stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed', 'C:\xampp\htdocs\coparmex\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php', '94', array())
at stream_socket_enable_crypto(resource, true, '9') in StreamBuffer.php line 94
at Swift_Transport_StreamBuffer->startTLS() in EsmtpTransport.php line 313
at Swift_Transport_EsmtpTransport->_doHeloCommand() in AbstractSmtpTransport.php line 118
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 385
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 171
And this only happends in my localhost, in the web host works fine. I don't understand what is going on :c
These are my gmail settings
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=gmail
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
That's an error with your SSL certificate. You're trying to use a SSL connection (encrypted, secure connection) without a proper certificate.
That's because you're connecting from localhost, which isn't secure, and that is blocked by the connection. You could avoid that by changing your localhost connection to a SSL based one.
See this link for more details.
You should add below code in /config/mail.php ( worked on laravel 5.4 )
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
as you should never change code in vendors as suggested by Sultan Ahmad
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. Be sure you fully understand the security issues before using this as a solution.
I had the same issue and was able to resolve by removing a level of authentication security. That is, at some point Gmail asked me for the phone number - 2nd level of authentication. When I deleted this 2nd level I was happy again. I hope I have helped.
Hi I have also found this very useful on the server level:
Edit \vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
line 259 ish. comment out the $options = array(); and add the below.
$options = array();
$options['ssl'] = array('verify_peer' => false,
'verify_peer_name' => false, 'allow_self_signed' => true);
This work with Laravel 6.0
in Laravel : this will solve the problem.
go to \vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
inside method
private function establishSocketConnection()
after this code
$options = array();
if (!empty($this->params['sourceIp'])) {
$options['socket']['bindto'] = $this->params['sourceIp'].':0';
}
then add this two lines
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;