Laravel Email Verification, Password Resets & Custom Mailables

Transactional emails (verifying newly registered email addresses, sending password reset links, order invoices, security alerts) are critical functions of any web service. In this class, you will explore Laravel's native MustVerifyEmail contract, password reset tokens, generating custom Markdown Mailables, and testing local email delivery with Mailpit.

1. Enabling Native Email Verification

To enforce email verification for newly registered users, open app/Models/User.php and implement the MustVerifyEmail interface contract:

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    // ...
}

Next, attach the verified middleware to any route that requires a confirmed email address:

Route::get('/vip/exclusive-downloads', [VipController::class, 'index'])
    ->middleware(['auth', 'verified']);

If an unverified user tries to access this route, Laravel automatically redirects them to the email verification notice prompt!

2. Building a Custom Mailable with Markdown

Generate a dedicated mailable class with an HTML Markdown template:

php artisan make:mail WelcomeNewStudentMailable --markdown=emails.welcome

Inspect app/Mail/WelcomeNewStudentMailable.php:

<?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 WelcomeNewStudentMailable extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public User $user) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Welcome to the Veewom Learning Family!',
        );
    }

    public function content(): Content
    {
        return new Content(
            markdown: 'emails.welcome',
        );
    }
}

Edit the email view in resources/views/emails/welcome.blade.php:

<x-mail::message>
# Welcome, {{ $user->name }}!

Thank you for enrolling in the **Laravel Master Class 2026**. Your account has been activated.

<x-mail::button :url="route('dashboard')" color="success">
Access Student Dashboard
</x-mail::button>

Happy Coding,<br>
The Veewom Team
</x-mail::message>

3. Sending and Queueing Emails

Sending emails synchronously stalls your web server while it handshakes with the remote SMTP server. Always send emails asynchronously via Queues:

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeNewStudentMailable;

// 1. Send synchronously (blocks request for ~2 seconds)
Mail::to($user->email)->send(new WelcomeNewStudentMailable($user));

// 2. Queue asynchronously (Instant response! Handed to background queue worker)
Mail::to($user->email)->queue(new WelcomeNewStudentMailable($user));

Zero-Configuration Local Email Testing: Mailpit

In local development, configure your .env with MAIL_MAILER=smtp and MAIL_PORT=1025 to point to Mailpit (included by default in Laravel Sail and Herd). Mailpit catches all outgoing emails and lets you inspect HTML formatting and password reset links in a local browser UI at http://localhost:8025 without sending real emails.

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. How does the password reset token workflow operate?

When a user requests a reset, Laravel generates a 64-character cryptographic token, hashes it with SHA-256, and stores it in the password_reset_tokens table with a timestamp. The user clicks a signed email link containing the plaintext token to reset their password.

Q2. How do I preview a Mailable in the browser without sending it?

Return the mailable directly from a route: Route::get('/mailable-preview', fn() => new WelcomeNewStudentMailable(User::first()));. Laravel renders the exact HTML email in your browser.

Q3. Can I attach PDF files or binary invoices to Mailables?

Yes! In your Mailable class, add the attachments() method returning an array of Attachment objects: return [Attachment::fromPath(storage_path('invoice.pdf'))];.

Explore Related Laravel Tutorials & Next Steps

Broaden your backend architecture, REST API design, and enterprise production engineering expertise:

Authentication Starter Kits

Leverage built-in MustVerifyEmail interfaces on your Eloquent User model.

Queues & Async Mail Delivery

Send password reset links and verification emails asynchronously in background queues.

Security Best Practices for Passwords

Enforce strong password rules (mixed case, symbols, numbers) and token expirations.

Full Capstone Project Walkthrough

Inspect email delivery and customer verification in our enterprise capstone platform.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!