localhost and "stream_socket_enable_crypto(): SSL operation failed with code 1"

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Understanding and Resolving "stream_socket_enable_crypto(): SSL operation failed with code 1" Issues in Localhost Email Sending Body:

When it comes to developing applications that involve sending emails, using a localhost setup is an essential step before deploying the software on a live server. However, some users experience issues with their localhost email sending due to SSL certificate verification errors, as shown in this error message:

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

The issue occurs because your localhost lacks the necessary SSL certificates or configurations required for secure communication. In this context, we will examine the possible reasons behind this error message and provide solutions to resolve them.

Possible Causes

1. Invalid SSL Certificate: The SSL certificate installed on localhost might be self-signed or improperly configured, leading to verification failures in remote connections like Gmail's SMTP servers. In this case, you should import a trusted SSL certificate or use a commercial one from reputable providers such as Let's Encrypt. 2. Missing PHP Extensions: Your localhost setup might lack the necessary PHP extensions for establishing secure connections and enabling encryption. Ensure that your system has OpenSSL (openssl), SSL (ssl, ssl.dist), and other related extensions installed and properly configured. 3. Improper Configuration: The mail settings you provided (such as SMTP host, port, username, password, and encryption) may be incorrect or incompatible with the localhost environment. Double-check your configuration to ensure that they match the requirements for a successful connection. 4. Firewall Issues: Some firewalls might block secure connections, interfering with SSL certificate verification. Ensure that your firewall is properly configured, allowing access to the required ports (e.g., 587 or 465) and domains (smtp.gmail.com).

Solutions

1. Import a Trusted SSL Certificate: Follow these steps to import a trusted certificate on your localhost setup: a. Check the validity of the certificate by visiting https://www.sslshopper.com/ssl-server-checker.html. b. Download and install the certificate using a tool like OpenSSL or a Certificate Authority's provided instructions. c. Configure your PHP installation to use the new SSL certificate through php.ini file settings or the command line interface. 2. Enable Required PHP Extensions: Run the following command in your terminal to install the necessary extensions and modules for secure communication: `sudo apt-get install libssl-dev libcurl4-openssl-dev` This will allow you to use OpenSSL (openssl), SSL (ssl, ssl.dist), libcurl (libcurl), and related components in your web applications. 3. Correct Configuration: Ensure that all mail settings (host, port, username, password, encryption) are properly configured for localhost and match the requirements of your email service provider. If needed, adjust these settings to establish a secure connection with Gmail's SMTP server. 4. Allow Firewall Access: Review your firewall configuration to ensure that the necessary ports (e.g., 587 or 465) for SSL communication are open and accessible to the required domains (smtp.gmail.com). Adding exceptions in your firewall's settings should fix this issue.

Conclusion

In summary, resolving the "stream_socket_enable_crypto(): SSL operation failed with code 1" error on localhost requires addressing the underlying causes and ensuring proper configuration, PHP extensions, SSL certificate installation, and firewall access levels. By following these steps, you can successfully send emails using your localhost setup without any issues.