簡體   English   中英

Laravel 通知不發送 email 到 Mailtrap

[英]Laravel Notify doesn't send email to Mailtrap

我希望 Laravel 登錄系統在登錄網站后向我發送電子郵件。 這是我來自LoginController的經過authenticated的方法。

if ($user->hasTwoFactorAuthenticatedEnabled()) {
    auth()->logout();

    $request->session()->flash('auth', [
        'user_id' => $user->id,
        'using_sms' => false,
        'remember' => $request->has('remember')
    ]);

    if ($user->two_factor_type == 'sms') {
        $code = ActiveCode::generateCode($user);
        // Todo Send Sms
        $request->session()->push('auth.using_sms', true);
    }

    return redirect(route('2fa.token'));
}

$user->notify(new LoginToWebsiteNotification());

return false;

如您所見,我添加了$user->notify(new LoginToWebsiteNotification()); LoginToWebsiteNotification持有:

class LoginToWebsiteNotification extends Notification
{
    use Queueable;
    
    public function __construct()
    {
        //
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('u Loggedin')
            ->view('emails.login-to-website');
    }

    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

這里的問題是,登錄后,沒有任何東西發送到用戶的 email 地址。 請注意,郵件設置工作正常,我在新用戶在網站上注冊時對其進行了測試。 因此,如果您知道為什么此通知方法會向我發送 email,請告訴我; 我真的很感激你們的任何想法。

我希望 Laravel 登錄系統在登錄網站后向我發送電子郵件。 這是我來自LoginController的經過authenticated的方法。

if ($user->hasTwoFactorAuthenticatedEnabled()) {
    auth()->logout();

    $request->session()->flash('auth', [
        'user_id' => $user->id,
        'using_sms' => false,
        'remember' => $request->has('remember')
    ]);

    if ($user->two_factor_type == 'sms') {
        $code = ActiveCode::generateCode($user);
        // Todo Send Sms
        $request->session()->push('auth.using_sms', true);
    }

    return redirect(route('2fa.token'));
}

$user->notify(new LoginToWebsiteNotification());

return false;

如您所見,我添加了$user->notify(new LoginToWebsiteNotification()); LoginToWebsiteNotification持有:

class LoginToWebsiteNotification extends Notification
{
    use Queueable;
    
    public function __construct()
    {
        //
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('u Loggedin')
            ->view('emails.login-to-website');
    }

    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

這里的問題是,登錄后,沒有任何東西發送到用戶的 email 地址。 請注意,郵件設置工作正常,我在新用戶在網站上注冊時對其進行了測試。 因此,如果您知道為什么此通知方法會向我發送 email,請告訴我; 我真的很感激你們的任何想法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM