【问题标题】:Add email next to token in Laravel forgot password template email link (SOLVED)在 Laravel 中的令牌旁边添加电子邮件忘记密码模板电子邮件链接(已解决)
【发布时间】:2021-10-09 15:12:06
【问题描述】:

我正在使用带有身份验证系统的 Laravel 8.5。当用户想要更改密码时,它会发送一封带有链接的电子邮件。默认电子邮件包含如下所示的链接:

http://mywebsite/api/forgot-password?token=2ccece360b031db4dcadea0cbdf8dd47a1712632b727487a7226f19f8f607cc7&email=MyEmail%40gmail.com

我对电子邮件模板进行了一些更改。在 ResetPasswordNotification.php 我添加了这个:

public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->subject('MyApp password reset')
                    ->line('You are receiving this email because we received a password reset request for your account.')
                    ->action('Reset Password', $this->url)
                    ->line('This password reset link will expire in 60 minutes.')                    
                    ->line('If you did not request a password reset, no further action is required.');
    }

在 User.php 中我有:

public function sendPasswordResetNotification($token)
    {    
        $url = 'http://mywebsite/en/change-password?token=' . $token;    
        $this->notify(new ResetPasswordNotification($url));
    }

现在我收到了这个链接:

http://mywebsite/en/change-password?token=8f87fc2d504507as385b4c47cb015cee4192749d3f1d641863524d513abb2a39

仅包含令牌而不包含电子邮件。如何向其中添加电子邮件,使其看起来像这样:

http://mywebsite/en/change-password?token=8f87fc2d504507as385b4c47cb015cee4192749d3f1d641863524d513abb2a39&email=UserEmail@gmail.com

谢谢!

【问题讨论】:

  • 您只需将$url = 'http://mywebsite/en/change-password?token=' . $token; 更改为$url = 'http://mywebsite/en/change-password?token=' . $token . '&email=' . $this->email;(因为$this 将引用User.php 中的用户)。

标签: php laravel laravel-8 forgot-password


【解决方案1】:

尝试将电子邮件传递到 url。

public function sendPasswordResetNotification($token)
{    
    $url = 'http://mywebsite/en/change-password?token=' . $token . '&email=' .$this->email;    
    $this->notify(new ResetPasswordNotification($url));
}

【讨论】:

【解决方案2】:

只需在$token 旁边添加$this->email

public function sendPasswordResetNotification($token)
{    
    $url = 'http://mywebsite/en/change-password?token=' . $token . '&email=' . $this->email;    
    $this->notify(new ResetPasswordNotification($url));
}

【讨论】:

    猜你喜欢
    • 2015-06-13
    • 2018-08-17
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 2017-11-12
    • 2011-02-19
    相关资源
    最近更新 更多