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_SCHEMEdoes not match the port. Usesmtpswith 465 andsmtpwith 587. - “Failed to authenticate on SMTP server” (535): the username or password is wrong. With Mailcandor the username is
mailcandorand the password is your API key. - Old values still in use after editing
.env: the config is cached. Runphp artisan config:clearor rebuild the cache. - Queued mail never arrives: no worker is running, or
QUEUE_CONNECTIONissyncon one server and a real queue on another. Checkphp artisan queue:failedfor errors. - The Resend driver still calls Resend:
RESEND_BASE_URLis not set in the process environment (see the caveat above).
Testing and local development
MAIL_MAILER=logwrites every email tostorage/logs/laravel.loginstead of sending it.Mail::fake()in a test captures mail so you can assertMail::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.