New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
SMTP and APIUpdated 26 Oct 2026

Laravel Mail With SMTP: .env Settings, Mailables, Queues and Troubleshooting

Configure Laravel to send email over SMTP: the .env settings for Laravel 11 and earlier versions, mailables, queues, testing, common errors such as failed authentication and cached configuration, and deliverability.

KM
Written by Karan Malhotra
API and Developer Experience Lead
Reviewed by Tomasz Kowalski
  • Published19 May 2026
  • Read time7 min
  • Length1,434 words
Share this guide

Laravel has a clean mail system built on the Symfony Mailer component. You describe a message as a mailable class, point the framework at an SMTP server with a few lines in your .env file and send with one call. Most problems people report ("Laravel mail not sending", "failed to authenticate on SMTP server", "connection could not be established") come from the same few places: settings that do not match the port, an old cached configuration, special characters in a password and mail that runs in a web request instead of a queue. This guide covers the settings for current and older Laravel versions, a first mailable, queued sending, how to test safely, how to read the common errors and how to improve deliverability. Use the SMTP host, user name and password from your provider's dashboard. The values in the examples are placeholders.

.envMAIL_MAILER, MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD
SendMail::to($user)->send(new Welcome($user))
Scalequeue the mailable and run a worker

The .env settings

Laravel reads mail settings from config/mail.php, which in turn reads environment variables. The names changed slightly in Laravel 11, so check which version you run with php artisan --version.

# Laravel 11 and later
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your-smtp-user
MAIL_PASSWORD="your-smtp-password"
MAIL_SCHEME=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

# Laravel 10 and earlier
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your-smtp-user
MAIL_PASSWORD="your-smtp-password"
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

The difference is how encryption is chosen. In Laravel 10 and earlier, MAIL_ENCRYPTION=tls means STARTTLS on port 587 and ssl means implicit TLS on port 465. In Laravel 11 and later, the Symfony mailer uses STARTTLS automatically when the server offers it, and MAIL_SCHEME is only needed when you want implicit TLS on port 465: set it to smtps. Leave it empty or null for port 587. If you see an error about a wrong version number, the port and the scheme do not match. Our guide on which SMTP port to use explains why.

VariableMeaningNotes
MAIL_MAILERWhich driver to usesmtp for a relay, log to write mail to the log file during development, array in tests
MAIL_HOSTSMTP server nameCopy it from your provider, not from a tutorial
MAIL_PORTConnection port587 for STARTTLS, 465 for implicit TLS
MAIL_USERNAME / MAIL_PASSWORDCredentialsWrap the password in double quotes if it contains #, spaces or $
MAIL_FROM_ADDRESSDefault senderUse an address on a domain you have authenticated
MAIL_FROM_NAMEDefault sender nameShown to recipients, so keep it recognisable

A frequent trap is the hash sign. In an .env file, an unquoted # starts a comment, so a password that contains one is cut off and the server answers with an authentication error. Quote the value. A dollar sign can also be treated as a variable reference. If you build credentials into a connection string with MAIL_URL, percent-encode special characters, as described in SMTP error 535.

Clear cached configuration after every change

This is the single most common reason that "the settings are right but nothing changed". When you run php artisan config:cache, which is standard in production, Laravel stores the configuration in a file and stops reading .env at runtime. Editing .env afterwards has no effect until you rebuild the cache. Run these commands after any mail change, and restart queue workers, because a worker keeps the old configuration in memory.

php artisan config:clear
php artisan config:cache
php artisan queue:restart

Create and send a mailable

A mailable describes one kind of message. Generate it with Artisan, then fill in the envelope (subject and addresses), the content (the view) and any attachments.

php artisan make:mail WelcomeMail --markdown=emails.welcome
<?php

namespace App\Mail;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class WelcomeMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public User $user) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Welcome to ' . config('app.name'));
    }

    public function content(): Content
    {
        return new Content(markdown: 'emails.welcome', with: ['name' => $this->user->name]);
    }
}

Send it from a controller, a job or an event listener:

use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;

Mail::to($user->email)->send(new WelcomeMail($user));

Markdown mailables give you responsive HTML and a plain-text version from a single template, which suits transactional messages well. If you write your own HTML, add a text version as well, because filters penalise HTML-only mail. See HTML email templates for rendering tips.

Queue your mail

Sending inside the web request makes the user wait for an SMTP conversation, and a slow server slows your page. Queue the message instead. Either call Mail::to($user)->queue(new WelcomeMail($user)) or make the mailable implement ShouldQueue. Then run a worker with php artisan queue:work and keep it running under a process manager such as Supervisor or systemd. Use a real queue driver such as the database, Redis or SQS in production, because the sync driver runs jobs immediately and defeats the purpose.

Queued mail needs a plan for failures. Set $tries and a backoff so that temporary SMTP errors are retried with a growing delay, and let permanent errors fail quickly. Inspect failed jobs with php artisan queue:failed and retry them with php artisan queue:retry all once the cause is fixed. A queue that silently retries a rejected login every few seconds can trigger a provider block, so alert on repeated failures. Our guide rate limits, retries and backoff and the design notes in reliable email sending queues go deeper.

Test without sending real mail

  • Set MAIL_MAILER=log in local development. Messages are written to storage/logs/laravel.log so you can check content and headers.
  • Use Mail::fake() in automated tests, then assert that a mailable was sent or queued, without touching SMTP.
  • Send a one-line test from php artisan tinker to prove the connection and credentials before you debug your templates.
Mail::raw('SMTP test from Laravel', function ($m) {
    $m->to('[email protected]')->subject('SMTP test');
});

If this raw send works but your mailable does not, the problem is in the mailable or the queue, not in the SMTP settings. If it fails, read the exception message first, because Symfony Mailer is specific about the stage that failed.

Common errors and fixes

Error textUsual causeFix
Failed to authenticate on SMTP server with username ... using the authenticators ...Wrong credentials, unquoted special characters or the wrong credential typeRe-copy the credentials, quote the password in .env and clear the config cache
Connection could not be established with host ... timed outPort blocked by a firewall or the host name is wrongTest the host and port with openssl s_client from the same server
Unable to connect with STARTTLS / wrong version numberPort and encryption settings do not matchUse 587 with STARTTLS or 465 with smtps in Laravel 11 and later
Expected response code "250" but got code "550"The server rejected the sender or recipientRead the reply text. Use a verified From domain and a valid recipient
Mail works locally but not in productionCached config, a different .env or workers still using old valuesRun config:clear and queue:restart, and check the production .env
Queued mail never sendsNo worker is running or the queue name differsStart queue:work and check failed_jobs
Emails send but land in spamDomain not authenticated or poor contentPublish SPF, DKIM and DMARC and review the content

Deliverability for Laravel mail

Laravel gives you a correctly formed message. Whether it reaches the inbox depends on your domain and sending practices. Authenticate the domain in the From address with SPF, DKIM and DMARC, and test the result with the SPF, DKIM and DMARC checker. Keep password resets, receipts and alerts separate from newsletters, ideally on different subdomains, so that complaints about marketing mail cannot affect critical messages. Remove hard-bounced addresses from your user table or a suppression list rather than retrying them forever. Our guides on authenticating your domain and suppression lists explain both.

Finally, consider whether SMTP is the right transport as you grow. An email API gives you structured responses and event webhooks for delivered, bounced and complained messages, which you can store against your own records. Laravel's mail layer supports API-based transports through packages, and our comparison of SMTP and API sending helps you decide.

Send Laravel mail through a managed relay Copy the SMTP host and credentials from your dashboard and set your .env in minutes.

Explore the SMTP relay

References and further reading

Frequently asked questions

Why does Laravel not use my new .env mail settings?

If you ran config:cache, Laravel reads the cached configuration. Run php artisan config:clear, then config:cache again, and restart queue workers so they load the new values.

What is MAIL_SCHEME in Laravel 11?

It selects the transport scheme. Leave it empty for port 587 where STARTTLS is used automatically, and set it to smtps for implicit TLS on port 465.

Why does my password with a # fail?

In .env, an unquoted # starts a comment, so the password is cut off. Wrap the value in double quotes.

Should I queue emails in Laravel?

Yes for most applications. Queueing keeps pages fast and lets failed messages be retried. Use a real queue driver and keep a worker running.

How can I test Laravel mail locally?

Use MAIL_MAILER=log to write messages to the log, Mail::fake() in tests, and a raw send from tinker to confirm SMTP credentials.

Topics#laravel#php#smtp#queues#mailables#developers
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales