[英]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.