[Solved] Laravel 9 Email Error :Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with Code 1

Did you just stumble upon the Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1 ? Well, that’s because of the missing mail configuration. Read this blog post till the end to find the solution.

Recently, I 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. Things were going well… until my screen flashed – Unable to connect with STARTTLS: stream_socket_enable_crypto()

I dug up further to find the actual cause and found that Since I uploaded it to the server, I have my own SMTP, which isn’t working for me. I have the ssl authentication made, however, it is absolutely impossible that it will send me any mail. I get the following error:

routines:ssl3_get_server_certificate:certificate verify failed.

SSL working fine when i visit the site with https.

The Solution To Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1 

Step 1 :  If you have laravel version 8.x then Edit your .env file located in the root of the project The place where your mail settings are described, change tls or ssl to null. If you do not have such a line, then add MAIL_ENCRYPTION=null

Step 2 :  If you have version 8.x 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.

Step 3 : add following code to above code

Step 4 : Here Is Your Final code

Unable to connect with STARTTLS

Step 5 : Save the file.

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.Bingo! The error will be solved.

I hope the above-provided solution will be helpful to you in solving the Laravel 9 Email Error :Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1 ‘

Comment if you still have any queries or doubts. 🙂

Also, share this solution via social media with your developer friends.

Thanks for reading! 🍀


Leave a Reply

Your email address will not be published. Required fields are marked *