Introduction
Laravel’s mail system is powered by Symfony Mailer and supports SMTP, Mailgun, Postmark, Resend, Amazon SES, andsendmail out of the box.
Each type of email you send is represented as a mailable class. Mailables encapsulate all the configuration—who it’s from, the subject, the view, and attachments—in one place.
Configuration
Mail configuration lives inconfig/mail.php. Set the default driver and credentials via .env:
Popular mail drivers
After installing the package, set
MAIL_MAILER in .env to the driver name (mailgun, postmark, resend, or ses) and add the corresponding credentials to config/services.php.
Generating mailables
Create a mailable class with Artisan:app/Mail/OrderShipped.php.
Writing mailables
A mailable class defines three methods:envelope()— from address and subjectcontent()— the Blade view to renderattachments()— files to attach
Adding attachments
Attach files using theAttachment class:
Markdown mailables
Markdown mailables use Laravel’s pre-built email components to produce responsive, well-designed emails without writing custom HTML. Generate a Markdown mailable:resources/views/emails/orders/shipped.blade.php:
content method uses markdown instead of view:
Sending mail
Use theMail facade to send a mailable:
Queueing mail
Email sending can be slow. Queue the mailable to return a response immediately:ShouldQueue on the class:
Mail::to(...)->send(new OrderShipped($order)) queues automatically.
Specifying queue connection and name via PHP attributes
You can use PHP attributes to declare the queue connection and queue name directly on the mailable class, instead of chainingonConnection() and onQueue() at dispatch time:
Sending after the response
UseMail::to(...)->sendNow() or Mail::later() to control timing. To send right after Laravel returns the HTTP response:
Previewing mailables in the browser
Return a mailable from a route to inspect it during development:Testing mailables
Assert a mailable was sent without actually sending email:- Pest
- PHPUnit
Local development
During development, set thelog mailer to write all outgoing emails to your log file instead of sending them:
A complete example
1
Generate the mailable
2
Define the mailable class
3
Write the Blade template
4
Send after user registration
Notifications
Send multi-channel notifications—email, SMS, Slack, and database—with a single notification class.