What is Laravel Mail and How to use it

Hold on tight, everyone! Let’s discuss something amazing and super cool in the web development world: sending emails. Guess what? If you’re very cool with Laravel, you’re in a joyride because it makes sending emails as smooth and swift as butter on a hot skillet.

Honestly, for almost every web app , you’ll need to send emails. Consider the various scenarios: user registrations, password resets, order confirmations, and notifications—these are just a few examples. Laravel feels this, and that’s why its Mail feature is so mind-blowing.

Please explain the process of sending an email in Laravel. It’s as simple as making your morning coffee. Let’s cite some quick examples:

PHP

use Illuminate\Support\Facades\Mail;




Mail::raw('This is a simple email!', function ($message) {

    $message->to('user@example.com')->subject('Hello from Laravel!');

});

Boom! That’s it. With the help of a few lines of code, you’ve sent an email. Laravel’s Mail facade makes it incredibly easy. You can use the raw() process for simple and easier text emails like this. Please provide the body of your email and specify the recipient and subject in the closure. Isn’t it an easy-peasy method, right?

But what if you want to send something a little bit fancier, along with some HTML? Laravel has covered there too! Laravel allows you to create “Mailables.” You may consider them a blueprint for your emails. They help you to manage the email content and logic in a neat little class.

Suppose you want to send a welcome email to a new user. You may build a Mailable like this:

Bash

php artisan make:mail WelcomeUser

 

laravel mail artisan command

 

The above command will create a WelcomeUser.php file in your app/Mail directory. Inside this file, you can identify how your email should look. Here’s a basic instance:

PHP

namespace App\Mail;




use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Mail\Mailable;

use Illuminate\Mail\Mailables\Content;

use Illuminate\Mail\Mailables\Envelope;

use Illuminate\Queue\SerializesModels;




class WelcomeUser extends Mailable

{

    use Queueable, SerializesModels;




    public $name;




    /**

     * Create a new message instance.

     *

     * @return void

     */

    public function __construct(string $name)

    {

        $this->name = $name;

    }




    /**

     * Get the message envelope.

     */

    public function envelope(): Envelope

    {

        return new Envelope(

            subject: 'Welcome to our awesome platform!',

        );

    }




    /**

     * Get the message content definition.

     */

    public function content(): Content

    {

        return new Content(

            view: 'emails.welcome',

            with: [

                'name' => $this->name,

            ],

        );

    }




    /**

     * Get the attachments for the message.

     *

     * @return array<int, \Illuminate\Mail\Mailables\Attachment>

     */

    public function attachments(): array

    {

        return;

    }

}


See? It's well-structured. You ascertain  the subject in the envelope() process and the actual content in the content() process. 
Here, we're instructing  Laravel to use a Blade template called emails.
welcome to deliver the email body, and we're passing in a $name variable.

 

Then, in your controller or wherever you need to send the email, you can do this:

 

Laravel Mail

 

PHP

use App\Mail\WelcomeUser;

use Illuminate\Support\Facades\Mail;




Mail::to('newuser@example.com')->send(new WelcomeUser('John Doe'));

 

 

Read More Blog Posts:

Laravel Localization Guide: How to Build Multi-Language Apps in 2025

Laravel HTTP Client: The Easy Way to Make API Requests

Mastering Laravel Cookies: A Step-by-Step Guide | Laravel 12.x

 

Isn’t it cool? Laravel takes care of all the heavy lifting behind the scenes.

And try to guess what’s even cooler? Laravel helps you to use Markdown to write your email templates! This is because you can write your emails by using simple Markdown syntax, and Laravel will automatically convert it into excellent HTML emails. It also comes along with some pre-built themes to make your emails look professional without you having to write a ton of CSS. Just run:

Bash

php artisan vendor:publish --tag=laravel-mail

and you’ll find the Markdown mail templates in resources/views/vendor/mail/markdown. You can customize these to your heart’s content!

Laravel Mail is not just about sending basic emails. It is surrounded with features like

  • Attachments: It helps in easily attaching files to your emails.
  • Queueing: It send emails in the background so your users don’t have to await for long.
  • Custom Headers: If needed you might add any custom headers for working.
  • Testing: Mock your mailers to easily test your email sending logic.

In an honest review, Laravel has made sending emails such spontaneous way that it almost feels like cheating! So, next time when you need to send an email in your Laravel application, don’t forget how easy and strong the Mail feature is. You’ll be sending out those notifications and confirmations like a pro in no time. Keep on creating  awesome stuff!