Chi*_*235 18 php email laravel laravel-5.3
我是Laravel的初学者.目前我正在学习这个框架.我的Laravel版本是5.3.
我正在通过使用php artisan make:authAll工作正常搭建我的auth .我还在我的.env文件中配置了gmail smtp,在config directgory中配置了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
Ris*_*ana 61
您可以更改密码重置电子邮件主题,但需要一些额外的工作.首先,您需要创建自己的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.');
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以使用artisan命令生成通知模板:
php artisan make:notification ResetPassword
Run Code Online (Sandbox Code Playgroud)
或者您只需复制粘贴上面的代码即可.您可能会注意到此通知类与默认类非常相似Illuminate\Auth\Notifications\ResetPassword.实际上,您可以从默认ResetPassword类中扩展它.
唯一的区别在于,您添加了一个新的方法调用来定义电子邮件的主题:
return (new MailMessage)
->subject('Your Reset Password Subject Here')
Run Code Online (Sandbox Code Playgroud)
其次,在您的app\User.php文件中,您需要覆盖sendPasswordResetNotification()由Illuminate\Auth\Passwords\CanResetPasswordtrait 定义的默认方法.现在你应该使用自己的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));
}
}
Run Code Online (Sandbox Code Playgroud)
现在您的重置密码电子邮件主题应该更新!
希望这有帮助!
您可以轻松修改用于向用户发送密码重置链接的通知类.要开始使用,请覆盖sendPasswordResetNotificationUser模型上的方法.在此方法中,您可以使用您选择的任何通知类发送通知.密码重置$token是方法收到的第一个参数,请参阅自定义文档
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
在Laravel 5.7默认实现中与此类似:
return (new MailMessage)
->subject(Lang::getFromJson('Reset Password Notification'))
->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
->line(Lang::getFromJson('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.users.expire')]))
->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
Run Code Online (Sandbox Code Playgroud)
您所要做的就是将您的localefromconfig/app.php例如更改为ro,然后在您的resources/lang中创建一个ro.json类似于以下内容的文件:
{
"Reset Password Notification": "Via?a Medical? CMS :: Resetare parol?",
"Hello!": "Salut,",
"You are receiving this email because we received a password reset request for your account.": "Prime?ti acest email deoarece am primit o solicitare de resetare a parolei pentru contul t?u.",
"Reset Password": "Resetez? parola",
"This password reset link will expire in :count minutes.": "Acest link va expira în :count de minute.",
"If you did not request a password reset, no further action is required.": "Dac? nu ai solicitat resetarea parolei, nu este necesar? nicio alt? ac?iune.",
"Regards": "Toate cele bune",
"Oh no": "O, nu",
"Whoops!": "Hopa!",
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)": "Dac? nu reu?e?ti s? dai click pe butonul de \":actionText\", d? copy-paste la URL-ul de mai jos în browser:\n [:actionURL](:actionURL)"
}
Run Code Online (Sandbox Code Playgroud)
它将翻译主题(第一个键)和邮件正文。
Laravel 6.* 更新
这也可用于VerifyEmail.php通知。
小智 5
拉拉维尔 8
在 AuthServiceProvider.php 中
添加这些代码。
ResetPassword::toMailUsing(function ($notifiable, $url) {
return (new MailMessage)
->subject(Lang::get('Reset Password Notification'))
->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
->action(Lang::get('Reset Password'), $url)
->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')]))
->line(Lang::get('If you did not request a password reset, no further action is required.'));
});
Run Code Online (Sandbox Code Playgroud)