How to change reset password email subject in laravel?(如何在laravel中更改重置密码的电子邮件主题?)
问题描述
我是 Laravel 的初学者.目前我正在学习这个框架.我当前的 Laravel 版本是 5.3.
我正在使用 php artisan make:auth
搭建我的身份验证,一切正常.我还在我的 .env 文件中配置了 gmail smtp,在配置目录中配置了 mail.php.一切都完美无缺.但是我看到默认情况下忘记密码的电子邮件主题是 Reset Password
.我想改变它.
我看到了一些博客.我找到了一些博客.我已经在我的网站中实现了它.但同样的输出来了.
我点击了这些链接 -
希望对您有所帮助!
I am beginner in Laravel. Currently I am learning this framework. My curent Laravel version is 5.3.
I am scaffolding my auth by using php artisan make:auth
All are working fine. Also I configured gmail smtp in my .env file and mail.php in config directgory. All are perfectly working. But I saw by-default the forgot password email subject is going Reset Password
. I want to change that.
I saw some blog. I found some blog. I have implement that in my site. But same output coming.
I followed these links -
https://laracasts.com/discuss/channels/general-discussion/laravel-5-password-reset-link-subject
https://laracasts.com/discuss/channels/general-discussion/reset-password-email-subject
https://laracasts.com/discuss/channels/laravel/how-to-override-message-in-sendresetlinkemail-in-forgotpasswordcontroller
You can change your password reset email subject, but it will need some extra work. First, you need to create your own implementation of ResetPassword
notification.
Create a new notification class insideappNotifications
directory, let's named it ResetPassword.php
:
<?php
namespace AppNotifications;
use IlluminateNotificationsNotification;
use IlluminateNotificationsMessagesMailMessage;
class ResetPassword extends Notification
{
public $token;
public function __construct($token)
{
$this->token = $token;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Your Reset Password Subject Here')
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
}
You can also generate the notification template using artisan command:
php artisan make:notification ResetPassword
Or you can simply copy-paste the above code. As you may notice this notification class is pretty similar with the default IlluminateAuthNotificationsResetPassword
. You can actually just extend it from the default ResetPassword
class.
The only difference is here, you add a new method call to define the email's subject:
return (new MailMessage)
->subject('Your Reset Password Subject Here')
You may read more about Mail Notifications here.
Secondly, on your appUser.php
file, you need to override the default sendPasswordResetNotification()
method defined by IlluminateAuthPasswordsCanResetPassword
trait. Now you should use your own ResetPassword
implementation:
<?php
namespace App;
use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;
use AppNotificationsResetPassword as ResetPasswordNotification;
class User extends Authenticatable
{
use Notifiable;
...
public function sendPasswordResetNotification($token)
{
// Your your own implementation.
$this->notify(new ResetPasswordNotification($token));
}
}
And now your reset password email subject should be updated!
Hope this help!
这篇关于如何在laravel中更改重置密码的电子邮件主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在laravel中更改重置密码的电子邮件主题?
基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01