如何在laravel中发送电子邮件?

时间:2019-05-07 13:25:07

标签: php laravel

当我从数据库中删除用户时,我希望(作为管理员)向用户发送电子邮件! 谁知道该怎么做!  这是我的破坏功能

public function destroy($id)
{

    $thisuser = User::find($id);
    $thisuser->delete();
    Mail::send('admin.mails.activate', array_merge($data, ['user' => $user]), function ($message) use ($user) {
        $message->to($user->email)->subject('Account Deleted')->from('nesrinems97@gmail.com');
    });
    return redirect()->back();
}

1 个答案:

答案 0 :(得分:0)

将代码放入用户模型的此函数中,删除用户后将自动调用该代码:

protected static function boot()
{
    parent::boot();

    //catch delete
    static::deleting(function ($model) {
        $data = '...'; //(you still need to define this)
        Mail::send('admin.mails.activate', array_merge($data, ['user' => $model]), function ($message) use ($model) {
            $message->to($model->email)->subject('Account Deleted')->from('nesrinems97@gmail.com');
        });
    });
}