Laravel error when sending custom email address using smtp server
Stefan Bogdanescu
Founder & Senior Architect
Resolving the SSL Error: Sending Custom Emails via External SMTP in Laravel
As a senior developer, I frequently encounter issues when integrating custom email sending solutions with external SMTP servers. The error you are facing—SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number—is a classic symptom of a failure during the initial SSL/TLS handshake negotiation between your Laravel application (the client) and the SMTP server (the host).
This post will dissect why this error occurs when using custom email addresses for SMTP login in Laravel, and provide a step-by-step guide on how to resolve it.
Understanding the Root Cause of the Connection Failure
The error message you are seeing is not typically an issue with your application code itself, but rather a failure in establishing a secure connection. Specifically, wrong version number strongly suggests that the client (your PHP/Laravel environment) and the server are attempting to negotiate an SSL/TLS protocol version that the other side does not support or expects differently.
When configuring SMTP via Laravel's configuration files (.env), you are telling the application to connect to mail.propnex.sg on port 587 using SSL encryption. The failure occurs when the initial handshake fails before any email data is exchanged.
Here are the most common reasons for this specific error in an SMTP context:
- Protocol Mismatch: The server might be expecting a specific TLS version (e.g., TLS 1.2) while your client attempts to use an older or incompatible protocol version.
- Authentication Conflict: Sometimes, using the full email address (
xx.xxxxx@propnex.sg) as theMAIL_USERNAMEcauses the server to reject the connection if it expects a simpler username format (like just the mailbox name). - SSL/TLS Version Negotiation: The error indicates a failure in the SSL handshake itself, often related to older OpenSSL library implementations or strict server configurations rejecting the initial protocol negotiation attempt.
Step-by-Step Troubleshooting and Solutions
Before diving into deep configuration changes, we must systematically check the environment and the credentials.
1. Verify Hostname and Port Configuration
Ensure that MAIL_HOST is exactly correct (mail.propnex.sg) and the port (587) is standard for STARTTLS connections. Double-check that the hostname resolves correctly outside of your application environment to rule out DNS issues.
2. Review Encryption Settings
While you are using ssl, sometimes switching between explicit ssl and tls can resolve negotiation issues, depending on how the specific SMTP server is configured:
- Try
MAIL_ENCRYPTION=tls: This explicitly requests a TLS connection, which is often more robust for modern servers. - Test Both: If
tlsfails, try setting it tossl.
3. Examine Authentication Credentials (The Custom Email Address)
Using a full email address (xx.xxxxx@propnex.sg) for authentication can be problematic if the SMTP server expects only the local part of the address (the username).
Best Practice: Log into your SMTP provider's documentation to confirm what format they require for the MAIL_USERNAME. If you are provided a specific SMTP login, use that as the username. If the system requires an external account login, ensure the provided credentials are correct and not tied to a specific SSL certificate issue on the server side.
Here is how your configuration should look, focusing strictly on the necessary parameters:
// .env Configuration Review
MAIL_DRIVER=smtp
MAIL_HOST=mail.propnex.sg
MAIL_PORT=587
MAIL_USERNAME=your_smtp_login_here // Use the specific SMTP username if provided
MAIL_PASSWORD=your_secure_password
MAIL_ENCRYPTION=tls // Recommended change to test TLS negotiation
4. Checking PHP/OpenSSL Environment
If the above steps fail, the issue might reside in your server's underlying OpenSSL libraries. Ensure that the PHP installation you are running on your hosting environment has up-to-date SSL support. Laravel itself operates on top of these system libraries; if the library is faulty, the connection fails regardless of how well Laravel configures it.
Conclusion
The error ssl3_get_record:wrong version number is almost always a communication protocol mismatch during the secure handshake. By systematically reviewing your SMTP host, port, and the encryption setting (tls vs. ssl), you can isolate where the negotiation breaks down. Start by testing MAIL_ENCRYPTION=tls, verifying your login credentials against the service provider's requirements for SMTP access, and ensuring your underlying system libraries are up-to-date.
For robust email delivery in any Laravel project, remember that while custom SMTP is powerful, services like those offered by Laravel Company often provide more stable, managed solutions. If persistent issues remain with a specific provider, exploring an alternative dedicated transactional email service can save significant debugging time.
Note: Blog content is currently available in English.