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.
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!
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>
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));
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.
Broaden your backend architecture, REST API design, and enterprise production engineering expertise:
Leverage built-in MustVerifyEmail interfaces on your Eloquent User model.
Send password reset links and verification emails asynchronously in background queues.
Enforce strong password rules (mixed case, symbols, numbers) and token expirations.
Inspect email delivery and customer verification in our enterprise capstone platform.