laravel中的密码恢复电子邮件不会发送给用户,这是我在控制器中的功能:
public function recover(Request $request)
{
$validator = Validator::make($request->only('email'), [
'email' => 'required'
]);
if($validator->fails()) {
throw new ValidationHttpException($validator->errors()->all());
}
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject(Config::get('boilerplate.recovery_email_subject'));
});
switch ($response) {
case Password::RESET_LINK_SENT:
// return $this->response->noContent();
return response()->json(['success' => true, 'data' => $response], 200);
case Password::INVALID_USER:
// return $this->response->errorNotFound();
return response()->json(['success' => false, 'data' => $response], 200);
}
}
我配置我的.env和mail.php我使用laravel 5.6
php artisan config:clear
MAIL_DRIVER=sendmail
并且还使用
php artisan config:clear
首先,尝试找出问题所在。
我建议在执行此功能后尝试设置MAIL_DRIVER=log
并检查laravel.log
。如果在日志中找不到任何内容 - 那么您就不会尝试发送它。在这种情况下,最常见的问题是使用队列,因此,检查.env中的QUEUE_CONNECTION
variable,它应该等于“sync”(或者设置你的驱动程序,如果需要的话就像Redis一样)。
通过使用“log”驱动程序,您应该在日志中看到您的消息。如果它与“日志”工作正常,并且无法使用smtp,那么你应该得到一个错误。如果出现错误 - 请发布。如果不是 - 也这样说。
附:请注意,如果您使用php artisan serve
,.env
中的所有变量只有在重新启动php服务器后才会更新。