Laravel 5.8:如何在用户单击验证链接后发送电子邮件

7

我使用php artisan make:auth实现了身份验证系统,并已通过 Laravel 功能中的 MustVerify 设置用户电子邮件验证。

我希望在用户点击验证链接后发送另一封电子邮件(问候邮件)。我该如何做?


为什么不尝试事件监听器? - Abolfazl Mohajeri
1个回答

16
当用户注册时,会广播一个Illuminate/Auth/Events/Verified事件。
您可以使用此Artisan命令生成侦听器。
php artisan make:listener SendWelcomeMail
在listener中,您可以在handle($event)函数中添加逻辑。
public function handle(Verified $event)
{
    Mail::to($event->user->email)->send(new Greeting());
}

然后你需要在EventServiceProvider中将监听器注册到事件中。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接