注意:这是laravel 5.4,它不只是使用PHP mail()。所以这不重复。
我正在尝试应用laravel重置密码系统。但是,我无法让它发挥作用。邮件系统工作,我的联系表格可以发送邮件。但是,重置密码始终无法发送。我的猜测是因为我的用户电子邮件字段名为username
。
因此,我的用户表格凭据使用的是username
和password
,而不是email
。
这是我的路线
// Only unauthenticated users
Route::group(['middleware' => 'guest', 'namespace' => 'Guest'], function() {
Route::post('auth/password-reset-request', 'ForgotPasswordController@sendResetLinkEmail');
Route::post('auth/password-reset', 'ResetPasswordController@reset');
Route::post('auth/login', 'UserController@login');
Route::get('forgot-password', 'ForgotPasswordController@NewPasswordRequestForm')
->name('password.request');
Route::get('make-new-password/{token}', 'ResetPasswordController@showResetForm')
->name('password.reset');
Route::get('login', 'UserController@getLogin');
});
这是控制器
namespace App\Http\Controllers\Guest;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
use App\Helpers\ViewHelper;
class ForgotPasswordController extends Controller{
use SendsPasswordResetEmails;
/**
* Display the form to request a password reset link.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm()
{
return view('emails.passwords');
}
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validateUsername($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('username')
);
return $response == \Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
/**
* Validate the email for the given request.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function validateUsername(Request $request)
{
$this->validate($request, ['username' => 'required|email']);
}
/**
* Get the response for a failed password reset link.
*
* @param \Illuminate\Http\Request
* @param string $response
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendResetLinkFailedResponse(Request $request, $response)
{
return back()->withErrors(
['username' => trans($response)]
);
}
/**
* Get the response for a successful password reset link.
*
* @param string $response
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendResetLinkResponse($response)
{
return back()->with('success_msg', trans($response));
}
刀片形式
{!! Form::open(['url' => 'auth/password-reset-request', 'method' => 'POST', 'id' => 'form-hypotheek-afsluiten', 'class' => 'reg-page']) !!}
@if($errors->any())
<div class="alert alert-danger fade in alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{!! $errors->first() !!}
</div>
@endif
@include('layout.formalert')
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" name="username" class="form-control">
@if($errors->has('email'))
{!! $errors->first('email', '<em for="email" class="invalid">:message</em>') !!}
@endif
</div>
<div class="row">
<div class="col-md-12">
<button class="btn-u pull-right" type="submit">Request new password</button>
</div>
</div>
{!! Form::close() !!}
它不断给我成功,但没有发送电子邮件,这让我很难过。没有错误,没有电子邮件。
有人能看出我做错了吗?谢谢你提前。