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

NoneNameDeveloper's avatar

How to create custom Email Verification Template | Laravel 5.7

Now I am starting using Laravel 5.7, and we know after upgrading to Laravel 5.7 added new feature Email Verification, So I saw method in this file:

laravel\framework\src\Illuminate\Auth\Notifications
. But I couldn't find template or blade for sending Verification template. How can I create or find it? I rad https://laravel.com/docs/5.7/verification#after-verifying-emails doc but I couldn't found anything about blading....

Edited

Updated: I solved this problem. For changing template you can do that::
Illuminate\Notifications\resources\views
Then change email.blade.php file. That's all!
0 likes
15 replies
martinbean's avatar
Level 80

@nonenamedeveloper Looking at the VerifyEmail notification class, you can specify a “to mail” callback that will be used to create the mail message.

So in your AppServiceProvider class, you could do:

namespace App\Providers;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        VerifyEmail::toMailUsing(function ($notifiable) {
            $verifyUrl = $this->verificationUrl($notifiable);

            // Return your mail here...
            return (new MailMessage)
                ->subject('Verify your email address')
                ->markdown('emails.verify', ['url' => $verifyUrl]);
        });
    }
}
4 likes
NoneNameDeveloper's avatar

@MARTINBEAN - Hi, Thanks, but when I trying this, I have some problem like this

Call to undefined method App\Providers\AppServiceProvider::verificationUrl()
How can i fix it? thanks!
brodos's avatar

Here's how I've done it.

If you only want to change the wording, then you can use the resources/lang/en.json, by using the english to english key:value.

If you want to change the the structure am the notification email, then you can do it this way:

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

The notification view is published to:

resources/views/vendor/email.blade.php

After this, you can go ahead and make any changes to the view. This will apply to all the notifications sent through the app, and not just the verify email one.

Cheers!

2 likes
ctyler's avatar

@martinbean

It looks like you can access the users details because the event is called from the user in vendor/laravel/framework/src/Illuminate/Auth/Listeners/SendEmailVerificationNotification.php

class SendEmailVerificationNotification
{
    /**
     * Handle the event.
     *
     * @param  \Illuminate\Auth\Events\Registered  $event
     * @return void
     */
    public function handle(Registered $event)
    {
        if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
            $event->user->sendEmailVerificationNotification();
        }
    }
}

I am assuming that means you can personalize the email? How would you access the user detail from the emails.verify markdown?

P.S. I just asked this question before I seen this post, sorry.

timgavin's avatar

For anyone in the future wondering how to do this. Open AppServiceProvider.php and enter the following.

AppServiceProvider

<?php

namespace App\Providers;

use Carbon\Carbon;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        VerifyEmail::toMailUsing(function ($notifiable) {
            $verifyUrl = URL::temporarySignedRoute(
                'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
            );

            return (new MailMessage)
                ->subject('Welcome!')
                ->markdown('emails.verify', ['url' => $verifyUrl]);
        });
    }

    public function register()
    {
        //
    }
}

The Email View

Then create a view at emails/verify.blade.php and add your content.

@component('mail::message')

Thank you for registering!

@component('mail::button', ['url' => $url])
Verify Email
@endcomponent


Regards,<br>
{{ config('app.name') }}

@endcomponent

Source: https://twitter.com/stefanbauerme/status/1037704501862559745/

1 like
tekkimariani's avatar

This helped me a lot. thank you.

If you also work in Laravel 5.8, here is a little hint:

The function call now also includes the URL. Therefore you can define the AppServiceProvider like this:

<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;

class AppServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Override the email notification for verifying email
        VerifyEmail::toMailUsing(function ($notifiable,$url){
            $mail = new MailMessage;
            $mail->subject('Welcome!');
            $mail->markdown('emails.verify-email', ['url' => $url]);
            return $mail;
        });
    }
    
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Best regards.

4 likes
amir94rp's avatar

thank you for this solution can you explin the custom password reset in this way?

netr's avatar

If you want to go one step further

        VerifyEmail::toMailUsing(function ($notifiable){
            $verifyUrl = URL::temporarySignedRoute(
                'verification.verify',
                Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
                [
                    'id' => $notifiable->getKey(),
                    'hash' => sha1($notifiable->getEmailForVerification()),
                ]
            );

            $user = User::whereEmail($notifiable->getEmailForVerification())->first();
            return (new MailMessage)
                ->subject('Welcome!')
                ->markdown('emails.verify-email', ['user' => $user, 'verifyUrl' => $verifyUrl]);
        });

Lets you pass in a user object, if you want to reference their name. Etc.

ChrissBott's avatar

That's a very important hint! Before adding the url as the second parameter to the callback I was getting a 404 error after clicking the verification link in the mail. Thanks a lot!

GuntarV's avatar

@martinbean , how do I generate a totally new Email Verification link? I am planning to have totally custom email, in which, I will need to provide the verification link.

Alfie's avatar

Change 'verification.verify' with your custom named route on this lines :

$verifyUrl = URL::temporarySignedRoute(
                'verification.verify',

And you pass the parameters for the url request in here:

		[
                    'id' => $notifiable->getKey(),
                    'hash' => sha1($notifiable->getEmailForVerification()),
                ]

Please or to participate in this conversation.