Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

SMTP mail server and STARTTLS not working

Hello,

A dev in the team has create an SMTP mail server with this configuration :

  • STARTTLS
  • 587

Tested from Thunderbird, it works fine.

But used from the Laravel application, I get this error.

Connection could not be established with host \"ssl://mx.xxxxx.com:587\": stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:0A00010B:SSL routines::wrong version number

To be used with Laravel, I have added this configuration in the .env file.

MAIL_MAILER=smtp
MAIL_HOST=mx.xxxxx.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=xxxxxxxxxxx	
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME=Yggdra

Can you help me what I should check ?

Thanks for your help.

V

0 likes
10 replies
JussiMannisto's avatar

Your .env file shows STARTTLS configuration, but it looks like Laravel is trying to connect with implicit TLS.

Have you cleared configuration and restarted queues after .env changes? What do you see when you run this:

art tinker --execute="dump(config('mail.mailers.smtp'))"
1 like
vincent15000's avatar

The application is in a docker container.

When using tinker to create a new user, the email is sent correctly.

But when using the application via the browser, I get the errors mentioned above.

What's strange is that it works locally, but not in production.

What should I check in production ?

Madelynn's avatar

Use MAIL_ENCRYPTION=tls on port 587 (no ssl:// in host). For implicit SSL, switch to 465 with ssl, then run php artisan config:clear.

1 like
vincent15000's avatar

I have solved the problem : I just have to let the MAIL_ENCRYPTION key empty in the .env file.

With exactly the same SMTP server used either from the application installed locally or the application installed on the production server.

It works locally with :

MAIL_ENCRYPTION=
MAIL_ENCRYPTION=null
MAIL_ENCRYPTION=tls

And it works on the production server only with :

MAIL_ENCRYPTION=
MAIL_ENCRYPTION=null

Can somebody help me understand why ?

Jsanwo64's avatar

MAIL_ENCRYPTION= (or null) works but MAIL_ENCRYPTION=tls fails beacuse your production SMTP server does not support STARTTLS on port 587.

1 like
Jsanwo64's avatar

Also verify and check the connection info from the SMTP mail provider. There will surely be a secure way to connect.

1 like
vincent15000's avatar

No ... there isn't a local and a remote SMTP server.

I meant the application installed locally and on the production server both use the same remote SMTP server.

Glukinho's avatar

Obviously, laravel treats null and tls different ways somewhere deep inside.

I have similar mail configuration (TLS on port 587) and everything works without MAIL_ENCRYPTION set at all.

1 like

Please or to participate in this conversation.