Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

meloku's avatar

Laravel Breeze - Sending Registration Emails + Email Customizations

I've been testing out laravel breeze and so far have ben liking it.

However, for starters I cannot seem to get the email verification to send automatically to the user after registration and cannot find where the email views/templates are stored for me to be able to modify, and I wouldn't be surprised if they were some place right in front of my face that I have been missing.

I know Breeze is very new, but if anyone can direct me to where the emails are being stored in what directory so I can customize them, that would help, and possibly to let me know if it is a bug or a default off setting that the verify email email is not being sent after registration.

Thank you

0 likes
15 replies
rodrigo.pedra's avatar
Level 56

Email verification is sent by your own application code, Laravel Breeze doesn't change that.

You can check your ./app/Providers/EventServiceProvider.php

For this event registration:

    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
    ];

That means when a Registered event is dispatched that listener will be executed.

Reference from laravel/laravel repo: https://github.com/laravel/laravel/blob/4931af14006610bf8fd1f860cea1117c68133e94/app/Providers/EventServiceProvider.php#L17-L21

The reason you might not been seen any notifications been sent is because you have to manually add a trait to your User model to hint Laravel you want it to send that notification. Take a look at what the SendEmailVerificationNotification does:

public function handle(Registered $event)
{
    if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
        $event->user->sendEmailVerificationNotification();
    }
}

Reference: https://github.com/laravel/framework/blob/f41c5da7c6b8db9959e16af10411cdbcba1d520a/src/Illuminate/Auth/Listeners/SendEmailVerificationNotification.php#L16-L21

So it first checks if the User instance implements the MustVerifyEmail, didn't yet verified their email, and if so sends the email.

The ./app/Models/User.php model Laravel ships with , has the MustVerifyEmail interface imported on the top, but the class itself does not implements it by default. It is a opt-in feature, which means you should add it manually:

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
// ...

 // needs to add the `implements` manually
class User extends Authenticatable implements MustVerifyEmail
{
    // ...

All of this is described with more detail in the docs:

https://laravel.com/docs/8.x/verification#introduction

Regarding the email template, the reason you can't find it is because it doesn't exist. The sendEmailVerificationNotification(...) method sends the VerifyEmail notification:

    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }

Reference: https://github.com/laravel/framework/blob/f41c5da7c6b8db9959e16af10411cdbcba1d520a/src/Illuminate/Auth/MustVerifyEmail.php#L36-L39

Which in turn builds up the message without a template:

protected function buildMailMessage($url)
{
    return (new MailMessage)
        ->subject(Lang::get('Verify Email Address'))
        ->line(Lang::get('Please click the button below to verify your email address.'))
        ->action(Lang::get('Verify Email Address'), $url)
        ->line(Lang::get('If you did not create an account, no further action is required.'));
}

https://github.com/laravel/framework/blob/f41c5da7c6b8db9959e16af10411cdbcba1d520a/src/Illuminate/Auth/Notifications/VerifyEmail.php#L62-L69

The way you could customize it is be overriding the sendEmailVerificationNotification(...) method in your app's User model, and send a different notification where you can build the email the way you need/want.

Hope it is helps.

10 likes
meloku's avatar

ugh. Your right, I was so caught up in trying to search specific breeze docs, that I missed out on the obvious laravel docs for the basic stuff, although I am still very new to the events, as it got to the point where I was reading in circles trying to find what I thought I was looking for.

This is a ton of very useful information, and I'll be able to make some adjustments now.

Thank you so much,

1 like
rotaercz's avatar

I heard if you edit anything inside the vendor folder, whenever you run a Composer update it will overwrite any of your changes when the files update. Is it ok to modify files in the vendor folder in regards to that MailMessage?

EDIT: What's the best way to add/modify class functionality for files in the vendor folder?

1 like
rodrigo.pedra's avatar

No, never rely on vendor folder edits. its not meant to be changed or edited.

Also there is no need to edit MailMessage, this class is basically a message builder.

To change the verification email content you need to create a new notification class, and override the User model's sendEmailVerificationNotification(...) method to use send new notification class instead of the VerifyEmail class from the Laravel core.

In your new notification class you can even extend from VerifyEmail and just override (change) the buildMailMessage($url) method.

Pretty much what I already described above.

To learn more on creating and sending notifications the docs about it are pretty good:

https://laravel.com/docs/8.x/notifications

1 like
rotaercz's avatar

override the User model's sendEmailVerificationNotification(...) method...

I guess I don't understand this part. I looked in app\Models\User.php but I don't see a sendEmailVerificationNotification() method. What am I misunderstanding?

EDIT: Ah, I realized it implements MustVerifyEmail. Brainfart!

rodrigo.pedra's avatar

1 - ./app/Models/User extends Illuminate\Foundation\Auth\User

use Illuminate\Foundation\Auth\User as Authenticatable; // <<< it is aliased here

class User extends Authenticatable implements MustVerifyEmail
{

2 - Illuminate\Foundation\Auth\User uses the Illuminate\Auth\MustVerifyEmail trait

use Illuminate\Auth\MustVerifyEmail;

class User extends Model implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword, MustVerifyEmail;
}

3 - Trait Illuminate\Auth\MustVerifyEmail has the default sendEmailVerificationNotification() method

public function sendEmailVerificationNotification()
{
    $this->notify(new VerifyEmail);
}

-=-=-=-=-=-=-=-=-=-=-

In your app's User model just add a sendEmailVerificationNotification() method that sends your new notification class:

<?php

namespace App\Models;

use App\Notifications\MyVerificationNotification;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use HasFactory;
    use Notifiable;

    // ... other code in User model

    public function sendEmailVerificationNotification()
    {
        $this->notify(new MyVerificationNotification());
    }
}
3 likes
rotaercz's avatar

In your new notification class you can even extend from VerifyEmail and just override (change) the buildMailMessage($url) method.

Typically what folder would you place these new classes? Like should I make a folder that basically mirrors the vendor folder for these overrides?

EDIT: I want to say thank you for explaining things so well. You really understand Laravel on a deep level.

1 like
rodrigo.pedra's avatar

Thanks for the compliment. My pleasure to help.

I like to keep on the conventional folders. It makes things easier to find in the long run.

If you generate this notification using the artisan command it would place this notification on the./app/Notifications/, so I would keep it there.

1 like
Alfie's avatar

Adding on top of that, would you like to explain why MustVerifyEmail is an interface and not a trait ?

rodrigo.pedra's avatar

There is both an interface names MustVerifyEmail and a trait named MustVerifyEmail

Interface:

https://github.com/laravel/framework/blob/325a335ccf45426eabb27131ed48aa6114434c99/src/Illuminate/Contracts/Auth/MustVerifyEmail.php#L5

Trait:

https://github.com/laravel/framework/blob/325a335ccf45426eabb27131ed48aa6114434c99/src/Illuminate/Auth/MustVerifyEmail.php#L7

This is a common pattern in Laravel, have an interface used to define which methods are available, then you can easily typehint it, and use instanceof to check if the object implements that interface (has those methods).

And provide a trait with a default implementation to those methods defined in the interface.

The base User model ships with the trait applied:

https://github.com/laravel/framework/blob/325a335ccf45426eabb27131ed48aa6114434c99/src/Illuminate/Foundation/Auth/User.php#L14-L20

But to "tell" the framework it should use those methods on your local User model , you should opt-in to the feature by implementing the interface.

So in places like these, Laravel can check if it needs to run that feature or not:

https://github.com/laravel/framework/blob/325a335ccf45426eabb27131ed48aa6114434c99/src/Illuminate/Auth/Listeners/SendEmailVerificationNotification.php#L18-L20

https://github.com/laravel/framework/blob/325a335ccf45426eabb27131ed48aa6114434c99/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php#L23

Hope it helps making it clearer.

1 like
GilbertoDiaz's avatar

@rodrigo.pedra -- Even today, 2024, this thread has helped me create the Notification, add the public method to the User model, and call it successfully. I was even able to return a view instead. Thanks @rodrigo.pedra for so well explained answer.

1 like

Please or to participate in this conversation.