Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with self-signed TLS certificates in Laravel's SMTP driver?

I'm trying to send an email with this configuration:

return [

    'driver'     => 'smtp',

    'host'       => 'mail.mydomain.com',

    'port'       => 26,

    'from'       => ['address' => '[email protected]', 'name' => 'Mailer'],

    'encryption' => 'tls',

    'username'   => env('MAIL_USERNAME'),

    'password'   => env('MAIL_PASSWORD'),

    'sendmail'   => '/usr/sbin/sendmail -bs',

    'pretend'    => false,

];

When I submit the form I receive this erorr:

ErrorException in StreamBuffer.php line 95:
stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I found this solution where people seems to have solved the problem with the same library but I cant manage to solve it in Laravel.

https://github.com/PHPMailer/PHPMailer/issues/368

like image 873
Alan Avatar asked Jun 08 '15 16:06

Alan


People also ask

Can you use a self signed certificate for TLS?

If you want to secure your website with an SSL/TLS certificate, you can use a free self-signed SSL/TLS certificate.

How does TLS certificate validation work?

How does a TLS certificate work? When a user tries to connect to a server, the server sends them its TLS certificate. The user then verifies the server's certificate using CA certificates that are present on the user's device to establish a secure connection.


1 Answers

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.

Add this at bottom of your config/mail.php

'stream' => [
   'ssl' => [
       'allow_self_signed' => true,
       'verify_peer' => false,
       'verify_peer_name' => false,
   ],
],

this will solve your problem.

like image 110
M Arfan Avatar answered Sep 17 '22 17:09

M Arfan