如何編輯在重置密碼或驗證電子郵件地址時發送的電子郵件模板。示例電子郵件的圖片
uj5u.com熱心網友回復:
您應該更改 User 模型上的默認 Laravel sendPasswordResetNotification 方法。
因為這些行來自 Illuminate\Auth\Notifications\ResetPassword.php。永遠不要改變這個外觀。如果您這樣做,您可能會在 Laravel 更新期間丟失更改。
而不是這樣做,將以下內容添加到您的用戶模型中。
use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default).
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new PasswordReset($token));
}
創建創建該通知:
php artisan make:notification PasswordReset
以及此通知內容的示例:
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.') // Here are the lines you can safely override
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
uj5u.com熱心網友回復:
使用以下命令匯入電子郵件模板
php artisan vendor:publish --tag=laravel-mail
然后你可以在這個檔案夾中編輯你的 html/text 模板
resources/views/vendor/mail
https://laravel.com/docs/8.x/mail#customizing-the-components
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/329024.html
