Laravel Mail Cheat Sheet: Quick Reference for Sending Emails

This cheat sheet provides a concise reference for Laravel's Mail helper, covering basic sending methods, queueing options, delayed delivery, message configuration (recipients, subject, priority, attachments, embeds), and useful code snippets for rapid implementation.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Laravel Mail Cheat Sheet: Quick Reference for Sending Emails

Laravel's Mail class is a helper for sending email messages within a Laravel application.

Basic Sending and Queueing Methods

Mail::send('email.view', $data, function ($message) {});
Mail::send(['html.view', 'text.view'], $data, $callback);
Mail::queue('email.view', $data, function ($message) {});
Mail::queueOn('queue-name', 'email.view', $data, $callback);
Mail::later(5, 'email.view', $data, function ($message) {});
// Log the email instead of sending (useful for testing)
Mail::pretend();

Message Configuration Options

The $message instance passed to the callback supports a full set of methods to configure the email:

$message->from('[email protected]', 'Mr. Example');
$message->sender('[email protected]', 'Mr. Example');
$message->returnPath('[email protected]');
$message->to('[email protected]', 'Mr. Example');
$message->cc('[email protected]', 'Mr. Example');
$message->bcc('[email protected]', 'Mr. Example');
$message->replyTo('[email protected]', 'Mr. Example');
$message->subject('Welcome to the Jungle');
$message->priority(2);
$message->attach('foo\bar.txt', $options);
$message->attachData('bar', 'Data Name', $options);
$message->embed('foo\bar.txt');
$message->embedData('foo', 'Data Name', $options);
$message->getSwiftMessage();

These methods allow you to set sender and recipient details, customize the subject and priority, add file attachments or raw data, embed inline resources, and access the underlying SwiftMailer object for advanced manipulation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPLaravelEmailMailCheat Sheet
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.