gpt4 book ai didi

php - 如何在 Laravel 中更改重置密码电子邮件主题?

转载 作者:IT王子 更新时间:2023-10-29 00:14:11 24 4
gpt4 key购买 nike

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

我正在使用 php artisan make:auth 构建我的身份验证所有工作正常。此外,我在我的 .env 文件中配置了 gmail smtp,在 config directgor​​y 中配置了 mail.php。一切都很好。但我看到默认情况下忘记密码的电子邮件主题是 Reset Password。我想改变它。

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

我点击了这些链接 -

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

最佳答案

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

app\Notifications目录下新建一个通知类,我们将其命名为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.');
}
}

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

php artisan make:notification ResetPassword

或者您可以简单地复制粘贴上面的代码。您可能会注意到此通知类与默认的 Illuminate\Auth\Notifications\ResetPassword 非常相似。 .实际上,您可以从默认的 ResetPassword 类扩展它。

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

return (new MailMessage)
->subject('Your Reset Password Subject Here')

您可以阅读更多关于 Mail Notifications here 的内容.

其次,在您的app\User.php 文件中,您需要覆盖由Illuminate\Auth\Passwords\CanResetPassword 定义的默认sendPasswordResetNotification() 方法。特征。现在您应该使用自己的 ResetPassword 实现:

<?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));
}
}

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

Reset password email subject updated

希望对您有所帮助!

关于php - 如何在 Laravel 中更改重置密码电子邮件主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40574001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com