Don Noinongyao
Don Noinongyao

Reputation: 175

Laravel 5.8 : How to send email after user click verify link

I implemented auth system by php artisan make:auth and already setup user email verify by MustVerify from laravel feature

I want to send another email (Greeting mail) after user click verify link. How can I do that?

Upvotes: 7

Views: 2863

Answers (1)

Daniel
Daniel

Reputation: 11182

When a user is registered a Illuminate/Auth/Events/Verified event is broadcast.

You can use this artisan command to generate a listener

php artisan make:listener SendWelcomeMail

In the listener you can add logic to the handle($event) function.

public function handle(Verified $event)
{
    Mail::to($event->user->email)->send(new Greeting());
}

Then you register the listener with the event in the EventServiceProvider

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

Upvotes: 16

Related Questions