@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]);
});
}
}
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.
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.
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
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!
@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.