Frameworks

How to send email with Laravel

Short answer

Laravel sends email through its mail system, built on Symfony Mailer. Set MAIL_MAILER=smtp and the MAIL_SCHEME, MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD and MAIL_FROM_ADDRESS variables in .env, create a Mailable with php artisan make:mail, and send it with Mail::to()->send() or queue(). API drivers are also built in. Verify your sending domain with SPF, DKIM and DMARC.

Last checked 16 November 2026

Laravel sends email through its own mail system, which is built on Symfony Mailer. You pick a driver in .env (SMTP or one of the API drivers), write each email as a Mailable class, and send it with the Mail facade. The examples below match the current Laravel release, Laravel 13, and also apply to Laravel 11 and 12.

Option 1: SMTP (works with any provider)

.env settings

MAIL_MAILER=smtp
MAIL_SCHEME=smtps
MAIL_HOST=smtp.mailcandor.com
MAIL_PORT=465
MAIL_USERNAME=mailcandor
MAIL_PASSWORD=mc_live_xxxxxxxxxxxxxxxx
MAIL_FROM_ADDRESS="hello@acme.com"
MAIL_FROM_NAME="${APP_NAME}"

MAIL_SCHEME replaced the old MAIL_ENCRYPTION setting in Laravel 11. Use smtps for port 465, where TLS starts immediately. For port 587, set MAIL_SCHEME=smtp and MAIL_PORT=587; Symfony Mailer upgrades the connection with STARTTLS when the server offers it. If you upgraded from Laravel 10 and kept your old config/mail.php, check which keys it reads before changing .env.

With Mailcandor’s SMTP relay, the username is always mailcandor and the password is your API key.

After changing .env in production, run php artisan config:cache again, or the old values stay in the cached config.

Create a Mailable

php artisan make:mail WelcomeMail
<?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 Acme');
    }

    public function content(): Content
    {
        return new Content(
            view: 'mail.welcome',
            text: 'mail.welcome-text',
        );
    }
}

Public properties such as $user are available in the Blade views resources/views/mail/welcome.blade.php and welcome-text.blade.php. For quick, good-looking templates, php artisan make:mail WelcomeMail --markdown=mail.welcome generates a Markdown mailable instead.

Send it

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

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

send() waits for the SMTP server. To return the response straight away, queue it:

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

Queued mail needs a queue connection other than sync and a worker running php artisan queue:work.

Attachments

Add an attachments() method to the Mailable:

use Illuminate\Mail\Mailables\Attachment;

public function attachments(): array
{
    return [
        Attachment::fromStorage('invoices/1042.pdf')
            ->as('invoice-1042.pdf')
            ->withMime('application/pdf'),
    ];
}

Option 2: an API driver

Laravel’s documentation recommends API drivers where possible because they are usually simpler and faster than SMTP. Laravel ships drivers for Mailgun, Postmark, Resend and Amazon SES. None of them is a generic “any HTTP API” driver, so using one with a different provider only works if that provider accepts the same request shape and you can change the endpoint.

The Resend driver pointed at a compatible API

Mailcandor accepts Resend’s request shape at /v1/emails, and the resend/resend-php package that Laravel’s driver uses reads a RESEND_BASE_URL environment variable. That makes this setup possible:

composer require resend/resend-php
MAIL_MAILER=resend
RESEND_API_KEY=mc_live_xxxxxxxxxxxxxxxx
RESEND_BASE_URL=https://api.mailcandor.com/v1

config/services.php should contain the key mapping (it does in a new Laravel app):

'resend' => [
    'key' => env('RESEND_API_KEY'),
],

One caveat: the package reads RESEND_BASE_URL with PHP’s getenv(), not through Laravel’s config. Once you run php artisan config:cache, Laravel no longer loads .env, so in production set RESEND_BASE_URL as a real environment variable on the server (in your hosting panel, Forge site settings, systemd unit or container). If you cannot do that, use SMTP: it gives the same result with no caveats. The switch from Resend guide covers the compatible endpoint in more detail.

A plain HTTP call

For one-off emails outside the Mailable system, Laravel’s HTTP client is enough:

use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('MAILCANDOR_KEY'))
    ->withHeaders(['Idempotency-Key' => "order-{$order->id}-receipt"])
    ->post('https://api.mailcandor.com/v1/emails', [
        'from' => 'Acme <hello@acme.com>',
        'to' => $order->email,
        'subject' => "Receipt for order {$order->id}",
        'html' => view('mail.receipt', ['order' => $order])->render(),
    ])
    ->throw();

$id = $response->json('id');

In real code, read the key from config('services.mailcandor.key') rather than env(), because env() returns null once config is cached.

Common errors

  • “Connection could not be established with host”: the port is blocked or MAIL_SCHEME does not match the port. Use smtps with 465 and smtp with 587.
  • “Failed to authenticate on SMTP server” (535): the username or password is wrong. With Mailcandor the username is mailcandor and the password is your API key.
  • Old values still in use after editing .env: the config is cached. Run php artisan config:clear or rebuild the cache.
  • Queued mail never arrives: no worker is running, or QUEUE_CONNECTION is sync on one server and a real queue on another. Check php artisan queue:failed for errors.
  • The Resend driver still calls Resend: RESEND_BASE_URL is not set in the process environment (see the caveat above).

Testing and local development

  • MAIL_MAILER=log writes every email to storage/logs/laravel.log instead of sending it.
  • Mail::fake() in a test captures mail so you can assert Mail::assertSent(WelcomeMail::class).

Which should you choose?

SMTP mailer Resend driver (compatible endpoint) HTTP client
Works with Mailables and notifications Yes Yes No
Extra packages None resend/resend-php None
Config caveats None RESEND_BASE_URL must be a real env var None
Best for Most apps Moving off Resend without code changes One-off API calls

For most Laravel apps, SMTP is the safe choice. For the plain PHP versions, see the PHP email guide.

Before you send: verify your domain

MAIL_FROM_ADDRESS must be on a domain with SPF, DKIM and DMARC records, or your mail will be filtered. Add the domain with your provider, publish the records it gives you, and wait for verification. The SPF, DKIM and DMARC guide explains each one.

Questions

What are the Laravel mail SMTP settings in .env?

MAIL_MAILER=smtp, MAIL_SCHEME (smtps for port 465, smtp for 587), MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, MAIL_FROM_ADDRESS and MAIL_FROM_NAME.

What happened to MAIL_ENCRYPTION in Laravel?

Laravel 11 replaced it with MAIL_SCHEME in the default config/mail.php. Use smtps for implicit TLS on port 465, or smtp for port 587, where the connection upgrades with STARTTLS automatically.

Which Laravel mail drivers are there?

smtp, sendmail, mailgun, ses, ses-v2, postmark, resend, log and array, plus failover and roundrobin, which combine other mailers.

Can I use Laravel's Resend driver with another provider?

Only if the provider accepts Resend's API shape and you can change the endpoint. The resend/resend-php package reads a RESEND_BASE_URL environment variable, so it can point at a compatible API such as Mailcandor.

How do I send email in the background in Laravel?

Call Mail::to($user)->queue(new Mailable(...)) instead of send(), with a queue connection configured and a worker running php artisan queue:work.

How do I test Laravel email without sending it?

Set MAIL_MAILER=log locally to write emails to the log, and use Mail::fake() in tests to assert what was sent.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.