Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

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 show

Fix it fast

Most common cause, 1 of 2

MAIL_SCHEME is smtps while the port expects STARTTLS

Remove MAIL_SCHEME or set it to smtp for a STARTTLS port.

Fix
# .env
MAIL_SCHEME=smtp
MAIL_PORT=587

php artisan config:clear
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to Laravel 13.43 and 12 (MAIL_SCHEME, PHP 8.3 to 8.5), Symfony Mailer 8.1, OpenSSL 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
php artisan config:show mail

Then find the line you see in this list and open its fix:

  1. 1MAIL_SCHEME is smtps while the port expects STARTTLSconfig:show mail shows scheme smtps with port 587, 2525 or 25, and the host in the error starts with ssl://
  2. 2Port 465 is set for a server that does not use implicit TLS thereMAIL_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 number
  • Connection 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.

Check
grep -n '^MAIL_SCHEME\|^MAIL_PORT' .env
openssl s_client -starttls smtp -connect smtp.example.com:587 -brief

Fix

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.

Fix
# .env
MAIL_SCHEME=smtp
MAIL_PORT=587

php artisan config:clear

Verify

Sending again (for example the password reset form that failed) adds no new mail exception to the log.

Verify
tail -n 20 storage/logs/laravel.log

Confirmed by github.com

Did this fix it?

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.

Check
openssl s_client -connect smtp.example.com:465 -brief
openssl s_client -starttls smtp -connect smtp.example.com:587 -brief

Fix

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.

Fix
# .env, provider offers STARTTLS on 587
MAIL_PORT=587
MAIL_SCHEME=

php artisan config:clear

Verify

config:show mail lists the new port, and sending works.

Verify
php artisan config:show mail

Confirmed by raw.githubusercontent.com

Did this fix it?

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

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.