When upgrading an app from Laravel 11 to 12, Shift helpfully called out the MAIL_ENCRYPTION
environment variable is no longer used.
There is now a new MAIL_SCHEME
environment variable instead.
On the surface, the one seems to replace the other, but this is not the case.
Previously, MAIL_ENCRYPTION
could either be null
or tls
.
But the new MAIL_SCHEME
environment variable expects either null
, smtp
, or smtps
.
Most of my projects had the null
value, which is also the default in the app skeleton, so I didn't run into issues.
But one project had tls
set, so the app threw an error when I tried to send an email.
I could have just changed it from tls
to smtps
, but this made me dig a bit deeper.
Why is null
the default?
Don't we want encryption when sending email?
There's a blog post which explains SMTP port 465 versus 587 and the differences between smtps
and STARTTLS
, if you're really interested in the full history.
The short version is that the current industry standard is to use port 587 with STARTTLS
, which is the default behavior if you specify null
for MAIL_SCHEME
.
Laravel (and the underlying Symfony mail transport) will actually go a step further and use the older smpts
scheme automatically if you specify port 465, so you're covered either way.
My recommendation is to stick with the default and leave MAIL_SCHEME=null
in your .env
file, and let Laravel handle the rest.
Here to help,
Joel
P.S. You think this tip is good? You should try our free book of even more Laravel tips to make your application a little bit better.