Laravel mail opens TLS at once on a port that first speaks plain SMTP
Your error
stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:0A00010B:SSL routines::wrong version number1 more line it can showFix it fast
Most common cause, 1 of 2MAIL_SCHEME is smtps while the port expects STARTTLS
Remove MAIL_SCHEME or set it to smtp for a STARTTLS port.
# .env
MAIL_SCHEME=smtp
MAIL_PORT=587
php artisan config:clearShort answer
"stream_socket_client(): SSL operation failed with code 1 ... error:0A00010B:SSL routines::wrong version number" means the mailer began TLS on connect (smtps) but the server greeted in plain SMTP. It happens when MAIL_SCHEME=smtps meets port 587, 2525 or 25, or port 465 reaches a server without TLS there. Pair smtps with 465 and smtp with 587. Applies to Laravel 12 and 13.
Which cause do you have?
Print the mail settings Laravel loaded. The scheme and port together tell you which cause applies: smtps on anything but 465 is the first, an empty scheme with port 465 is the second.
php artisan config:show mailThen find the line you see in this list and open its fix:
- 1MAIL_SCHEME is smtps while the port expects STARTTLS
config:show mail shows scheme smtps with port 587, 2525 or 25, and the host in the error starts with ssl:// - 2Port 465 is set for a server that does not use implicit TLS there
MAIL_SCHEME is empty, MAIL_PORT is 465, and an openssl test of port 465 fails with the same wrong version number
What does the error look like?
stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:0A00010B:SSL routines::wrong version numberConnection could not be established with host "ssl://smtp.example.com:587"
Cause 1 of 2
MAIL_SCHEME is smtps while the port expects STARTTLS
You seeconfig:show mail shows scheme smtps with port 587, 2525 or 25, and the host in the error starts with ssl://
Check
This wrong version number error comes from asking for TLS on connect at a port that first sends a plain-text SMTP greeting. With scheme smtps, Symfony Mailer turns TLS on before any SMTP is spoken, and OpenSSL reports wrong version number when the first bytes it receives do not look like TLS at all. Submission ports such as 587 start in plain text and switch with STARTTLS.
grep -n '^MAIL_SCHEME\|^MAIL_PORT' .env
openssl s_client -starttls smtp -connect smtp.example.com:587 -briefFix
Remove MAIL_SCHEME or set it to smtp for a STARTTLS port. With smtp, the mailer upgrades the connection by itself when the server offers STARTTLS.
# .env
MAIL_SCHEME=smtp
MAIL_PORT=587
php artisan config:clearVerify
Sending again (for example the password reset form that failed) adds no new mail exception to the log.
tail -n 20 storage/logs/laravel.logConfirmed by github.com
Cause 2 of 2
Port 465 is set for a server that does not use implicit TLS there
You seeMAIL_SCHEME is empty, MAIL_PORT is 465, and an openssl test of port 465 fails with the same wrong version number
Check
With no scheme set, Laravel picks smtps for port 465 and smtp for every other port. If the server you reach on 465 answers in plain text, for example a local test mail server or a relay set up without implicit TLS, the connection fails just as in the first cause, even though .env never mentions smtps.
openssl s_client -connect smtp.example.com:465 -brief
openssl s_client -starttls smtp -connect smtp.example.com:587 -briefFix
Use the port and method your mail provider documents, often STARTTLS on 587. Changing only the scheme is not enough: Symfony Mailer also treats port 465 as implicit TLS when the scheme is smtp and automatic TLS is on, as it is by default.
# .env, provider offers STARTTLS on 587
MAIL_PORT=587
MAIL_SCHEME=
php artisan config:clearVerify
config:show mail lists the new port, and sending works.
php artisan config:show mailConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Write MAIL_SCHEME and MAIL_PORT as a pair in .env.example with a comment (smtps with 465, smtp with 587), so a copied config cannot mix them.
- When upgrading from Laravel 10, replace MAIL_ENCRYPTION with MAIL_SCHEME; current MailManager no longer reads the encryption key.
- Test a new mail host from the server with openssl s_client before pointing Laravel at it.
Sources
- Laravel framework 13.x: MailManager (scheme from port 465)
- Laravel skeleton 13.x: config/mail.php (MAIL_SCHEME)
- Symfony Mailer: EsmtpTransportFactory (smtps turns on TLS)
- Symfony Mailer: EsmtpTransport (port 465 means implicit TLS)
- Symfony Mailer: SocketStream (ssl:// and stream_socket_client)
- Symfony 8.1 docs: Mailer (automatic STARTTLS)
- OpenSSL source: non-TLS first record gives WRONG_VERSION_NUMBER
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.