如何更改laravel中的重置密码电子邮件主题? [英] How to change reset password email subject in laravel?

查看:298
本文介绍了如何更改laravel中的重置密码电子邮件主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的初学者。目前我正在学习这个框架。我的治疗Laravel版本是5.3。



我使用脚手架我的认证php artisan make:auth 精细。另外我在我的.env文件中配置了gmail smtp,并在config directgor​​y中配置了mail.php。都是完美的工作。但是我看到默认密码电子邮件主题正在进行重置密码。我想改变那个。



我看到一些博客。我找到一些博客我在我的网站上实现了。但是同样的输出来了。



我遵循这些链接 -



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 / discussion / channels / laravel / how-to-override-message-in-sendresetlinkemail-in-forgotpasswordcontroller

解决方案

您可以更改密码重置电子邮件主题,但需要额外的工作。首先,您需要创建自己的 ResetPassword 通知。



app \Notifications中创建一个新的通知类目录,让我们命名为 ResetPassword.php

 <?php 

命名空间App \Notifications;

使用Illuminate\Notifications\Notification;
使用Illuminate\Notifications\Messages\MailMessage;

class ResetPassword extends Notification
{
public $ token;

public function __construct($ token)
{
$ this-> token = $ token;
}

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


公共功能toMail($通知)
{
返回(新的MailMessage)
- >主题('您的重置密码主题在这里' )
- > line('您收到此电子邮件是因为我们收到您的帐户的密码重置请求。'
- > action('Reset Password',url('password / ,$ this-> token))
- > line('如果您没有请求重置密码,则不需要进一步的操作。
}
}

您还可以使用artisan命令生成通知模板:

  php artisan make:notification ResetPassword 

或者你可以简单地复制粘贴上面的代码。正如你可能会注意到这个通知类是使用默认的 Illuminate\Auth\Notifications\ResetPassword 。您实际上可以从默认的 ResetPassword 类扩展它。



唯一的区别是这里,您添加一个新的方法调用来定义电子邮件的主题:

 return(new MailMessage)
- > subject('你的重置密码主题在这里')

您可以在这里阅读有关邮件通知的更多信息。



其次,在您的 app \User.php 文件中,您需要覆盖默认的 sendPasswordResetNotification() Illuminate\Auth\Passwords\CanResetPassword trait。现在,你应该用你自己的 ResetPassword 执行:

 < PHP 

命名空间应用程序;

使用Illuminate\Notifications\Notifiable;
使用Illuminate\Foundation\Auth\User作为Authenticatable;
使用App \Notifications\ResetPassword作为ResetPasswordNotification;

class用户扩展Authenticatable
{
使用Notifiable;

...

public function sendPasswordResetNotification($ token)
{
//您自己的实现。
$ this-> notify(new ResetPasswordNotification($ token));
}
}

现在,您的重置密码电子邮件主题应该更新!





希望这个帮助!


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 insideapp\Notifications directory, let's named it ResetPassword.php:

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

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 Illuminate\Auth\Notifications\ResetPassword. 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 app\User.php file, you need to override the default sendPasswordResetNotification() method defined by Illuminate\Auth\Passwords\CanResetPassword trait. Now you should use your own ResetPassword implementation:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\ResetPassword 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中的重置密码电子邮件主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆