我正在使用Laravel 5.3並自定義密碼重置電子郵件模板。我做了以下更改,以使用自定義Mailable類創建我自己的HTML電子郵件通知。這是我迄今取得的進展:自定義重置密碼電子郵件並在Laravel 5.3中傳遞用戶數據
ForgotPasswordController:
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return Response::json(['status' => trans($response)], 200);
case Password::INVALID_USER:
return Response::json(['email' => trans($response)], 400);
}
}
用戶模型:
public function sendPasswordResetNotification($token)
{
Mail::queue(new ResetPassword($token));
}
ResetPassword可郵寄類:
protected $token;
public function __construct($token)
{
$this->token = $token;
}
public function build()
{
$userEmail = 'something'; // How to add User Email??
$userName = 'Donald Trump'; // How to find out User's Name??
$subject = 'Password Reset';
return $this->view('emails.password')
->to($userEmail)
->subject($subject)
->with([
'token' => $this->token
'userEmail' => $userEmail,
'userName' => $userName
]);
}
如果您發現上述內容,我不確定如何傳遞用戶的姓名並找出用戶的電子郵件地址。我是否需要從用戶模型發送這些數據,或者從Mailable類中查詢它?有人能告訴我我該怎麼做嗎?
這不是很清楚。您何時或何時使用此電子郵件通知?我的意思是,你是否在用戶密碼重置之後使用它?或者你的意思是密碼重置電子郵件,其中包含重置密碼的鏈接?我說我可以幫你,但我根本不瞭解這種情況。 –
感謝您的關注@JulianRodriguez我正在嘗試在包含重置密碼錶單鏈接的密碼重置電子郵件中執行此操作。我用'ForgotPasswordController'更新了我的帖子。基本上我試圖將'Notification'替換爲'Mailable'類,以便在重置鏈接郵寄時爲此設置不同的html佈局。 – Neel