20

Greetings to the community!

I have recently developed a web page with Laravel 9.X, which works correctly in local, but when I upload it to my Host, I am having problems with sending emails.

When I have been testing locally, it has been working correctly, and I have been using mailtrap. Now that I have uploaded it to the server, I have my own SMTP, and it is not working for me. I have the ssl certificate created, but there is no way it will send me any mail. I get the following error:

Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed.

SSL working fine when i visit the site with https.

I have configured my .env file, where I have put:

HOST: my smtp server; PORT: 587; ENCRYPTION TYPE: SSL; USERNAME AND PASSWORD: Those of my email account.

I have been touching also my file located in config/mail.php, putting the same configuration as in the .env file. I have also tried with other ports like 25, 465... among others.

I have tried to access the mail account from outlook, using the IMAP protocol, and I have been able to connect correctly, so the mail can be accessed.

I have checked lot of things in Google, and also every blogs y found in Stack Overflow, but nothing worked.

Any idea what is going on? Am I missing something to configure?

1
  • The error says that the security certificate encountered when connecting to your email is invalid. Can you add more information about it? common name? SAN? certificate authority? Commented Apr 7, 2022 at 11:26

2 Answers 2

69

I had this problem after upgrading to the new 9 version, so you need to follow two steps.

  1. Edit your .env file located in the root of the project The place where your mail settings are described, change tls to null. If you do not have such a line, then add

    MAIL_ENCRYPTION=null

  2. If you have version 8 then this will be enough, but in version Laravel 9 you will need to open the file app/config/mail.php Find a section mailers smtp add two options 'auth_mode' => null and 'verify_peer' => false an example of how it would look

    'mailers' => [
             'smtp' => [
                 'transport' => 'smtp',
                 'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
                 'port' => env('MAIL_PORT', 587),
                 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
                 'username' => env('MAIL_USERNAME'),
                 'password' => env('MAIL_PASSWORD'),
                 'timeout' => null,
    
    
                 'auth_mode'  => null,
                 'verify_peer'       => false,
             ],
    
7
  • 4
    You are right, but in my case, i just needed to add 'verify_peer' => false, didnt put 'auth_mode' => null, and my encryptation type is ssl right now. It works correctly. Thank you
    – Maida
    Commented Apr 19, 2022 at 7:56
  • 7
    It works for me, actually because I upgrade my old version project to laravel 9, the Mail config is for the old version, and after updating it to the latest version, I set two parameters verify_peer and verify_peer_name with false value and my problem was solved Commented Jul 31, 2022 at 20:17
  • As the documentation (laravel.su/docs/9.x/upgrade) says, the auth_mode is not required but the verify_peer is needed to disable TLS peer verification. In my case setting verify_peer to false fixed the issue.
    – palinium
    Commented Jun 8, 2023 at 7:58
  • 2
    Don't forget to run php artisan config:cache after you make changes. Commented Oct 23, 2023 at 19:07
  • 1
    This is stupid and dangerous. Certificate verification is in place for a reason.
    – miken32
    Commented Apr 20 at 21:14
1

You could try changing the MAIL_MAILER value from smtp to sendmail in the .env file

Not the answer you're looking for? Browse other questions tagged or ask your own question.