我有成功消息,但忘记密码时没有收到电子邮件 laravel 5.6
I have success message but no email received in my forgot password laravel 5.6
这是我的成功消息,但我的邮箱中没有收到电子邮件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx@gmail.com
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=tls
我使用 mail_client 而不是电子邮件,所以我覆盖了一些功能,我还在我的客户端模型中添加了 this->mail_client
class ForgotPasswordController extends Controller{
use SendsPasswordResetEmails;
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
$response = $this->broker()->sendResetLink(
$request->only('mail_client')
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
protected function validateEmail(Request $request)
{$this->validate($request, ['mail_client' => 'required|email']);
}
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return back()->withErrors(
['mail_client' => trans($response)]
);
}
public function __construct()
{
$this->middleware('guest');
}}
最后我找到了答案:首先我需要将该方法(getEmailForPasswordReset 和 routeNotificationFor)覆盖到模型客户端中:
public function getEmailForPasswordReset()
{
return $this->mail_client;
}
public function routeNotificationFor($driver)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}();
}
switch ($driver) {
case 'database':
return $this->notifications();
case 'mail':
return $this->mail_client;
case 'nexmo':
return $this->phone_number;
}
}
并实施:
use Illuminate\Support\Str
进入 ForgotPasswordController 需要覆盖名为 sendResetLinkEmail 、validateEmail 和 sendResetLinkFailedResponse 的方法:
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(
$request->only('mail_client')
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
protected function validateEmail(Request $request)
{
$this->validate($request, ['mail_client' => 'required|email']);
}
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return back()->withErrors(
['mail_client' => trans($response)]
);
}
并且不要忘记更改 blade 中输入的姓名。
就这些了。
你安装postfix了吗?
尝试检查函数mail()是否成功;
也许您可以使用maildev 进行开发。
这是我的成功消息,但我的邮箱中没有收到电子邮件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx@gmail.com
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=tls
我使用 mail_client 而不是电子邮件,所以我覆盖了一些功能,我还在我的客户端模型中添加了 this->mail_client
class ForgotPasswordController extends Controller{
use SendsPasswordResetEmails;
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
$response = $this->broker()->sendResetLink(
$request->only('mail_client')
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
protected function validateEmail(Request $request)
{$this->validate($request, ['mail_client' => 'required|email']);
}
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return back()->withErrors(
['mail_client' => trans($response)]
);
}
public function __construct()
{
$this->middleware('guest');
}}
最后我找到了答案:首先我需要将该方法(getEmailForPasswordReset 和 routeNotificationFor)覆盖到模型客户端中:
public function getEmailForPasswordReset()
{
return $this->mail_client;
}
public function routeNotificationFor($driver)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}();
}
switch ($driver) {
case 'database':
return $this->notifications();
case 'mail':
return $this->mail_client;
case 'nexmo':
return $this->phone_number;
}
}
并实施:
use Illuminate\Support\Str
进入 ForgotPasswordController 需要覆盖名为 sendResetLinkEmail 、validateEmail 和 sendResetLinkFailedResponse 的方法:
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(
$request->only('mail_client')
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
protected function validateEmail(Request $request)
{
$this->validate($request, ['mail_client' => 'required|email']);
}
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return back()->withErrors(
['mail_client' => trans($response)]
);
}
并且不要忘记更改 blade 中输入的姓名。 就这些了。
你安装postfix了吗?
尝试检查函数mail()是否成功;
也许您可以使用maildev 进行开发。