Laravel 6 ForgotPasswordController无法发送密码重置邮件排查求助
Laravel 6 密码重置邮件无法发送,但其他邮件正常的排查问题
我正在调试一个Laravel 6应用,该应用无法向用户发送密码重置邮件,但其他邮件发送正常,更换邮件服务器也未解决问题。应用日志中无报错,输入有效邮箱时会返回重置邮件已成功发送的提示。
相关代码与配置情况
自定义的ForgotPasswordController
仅重写了sendResetLinkResponse和sendResetLinkFailedResponse方法以返回自定义JSON响应:
class ForgotPasswordController extends Controller { use SendsPasswordResetEmails; protected function sendResetLinkResponse(Request $request, $response) { return response()->json([...], 200); } protected function sendResetLinkFailedResponse(Request $request, $response) { return response()->json([...], 422); } }
调用的核心逻辑
接口调用了SendsPasswordResetEmails trait中定义的sendResetLinkEmail函数:
/** * Send a reset link to the given user. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse */ public function sendResetLinkEmail(Request $request) { $this->validateEmail($request); // We will send the password reset link to this user. Once we have attempted // to send the link, we will examine the response then see the message we // need to show to the user. Finally, we'll send out a proper response. $response = $this->broker()->sendResetLink( $this->credentials($request) ); return $response == Password::RESET_LINK_SENT ? $this->sendResetLinkResponse($request, $response) : $this->sendResetLinkFailedResponse($request, $response); }
该函数运行符合预期:输入有效邮箱时会调用重写的sendResetLinkResponse方法,且password_resets数据表中会生成记录。
模型与配置验证
- User模型已实现
CanResetPasswordContract并使用CanResetPasswordtrait,模型及数据库中的邮箱字段均为email。 - 曾排查
.env中的MAIL_FROM属性,但由于其他邮件发送正常,推测并非此原因:
MAIL_FROM_ADDRESS=email@test.com MAIL_FROM_NAME="My Application"
希望能得到排查方向的指引,感谢!
更新
排查代码后发现,所使用的通知实现了ShouldQueue接口,这正是既未发送邮件也无报错日志的原因。详情见下方回复。
内容的提问来源于stack exchange,提问作者rpanske
相关产品推荐
相关产品推荐

