SMTP for Laravel — application mail that arrives
Laravel ships with a full mail layer, including queues, templates and notifications. What it does not provide is deliverability: that depends on the server you send through, and the default configuration on a fresh server rarely makes a good sender.
Laravel reads its mail settings from the environment configuration. You change the SMTP details there and the rest of your application stays untouched — no changes to mailables, notifications or queues needed.
Why it goes wrong without a relay
An application in development sends to a test address and everything looks fine. At go-live the audience changes: real addresses at real providers, which do check authentication and reputation. That is the moment password reset emails suddenly stop arriving — for a subset of users, which makes it hard to spot.
Setting up SMTP in Laravel
Collect your details
Log in to your 2mail account and retrieve your SMTP server, username and password there.
Fill them in inside Laravel
The mail settings live in your application's environment file, not in the code. You set the mailer to SMTP and fill in the five details below. Do not forget the sender address and sender name: those are separate settings alongside the connection details.
Authenticate your domain
Make sure SPF, DKIM and DMARC are set correctly for your domain, so recipients can verify that the mail comes from you.
Test
Send a test message to an address at a major provider and check that it arrives in the inbox and not in the spam folder.
The fields Laravel asks for
Every platform names them slightly differently, but it is always the same five. The actual values are tied to your account and can be found in your 2mail account — take them from there, so you are sure to use the right ones.
| Field | What you enter |
|---|---|
| SMTP server (host) | The server name from your 2mail account. |
| Port | The port that matches your chosen encryption; your account shows which one. |
| Encryption | TLS. Never send unencrypted — your credentials would otherwise travel in plain text. |
| Username | The SMTP login of your 2mail account. |
| Password | The matching password. Never use the password of an employee's mailbox. |
Which emails Laravel sends
As soon as the relay is set up, all of these run through 2mail — you do not have to configure them one by one.
Pitfalls with Laravel
The queue has to be running
If you queue mail without an active worker, nothing leaves and you see no error at all. On a delivery problem this should be the first check, not the last.
Configuration cache after a change
If your application runs with a cached configuration, changed mail settings have no effect until that cache is refreshed. A setting that "does not work" often simply has not been re-read yet.
Test environments that really send
A staging environment with a copy of the production database can send to real customers unnoticed. Restrict the recipients there explicitly, or use a separate login.
A different platform?
SMTP is a standard protocol: any system that speaks SMTP — a CRM, an ERP, a custom application or a server — can send through 2mail using the same five fields.