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'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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
