Laravel 5.7 未发送验证电子邮件
Laravel 5.7 not sending verify emails
成功注册后,我的应用程序不发送验证电子邮件(它只发送到我域中的电子邮件),我被重定向到 /email/verify,就像它已发送一样(已检查垃圾邮件和促销文件夹)。另一方面,我的忘记密码系统工作得很好,所以我想我的 .env 很好。
这是我的身份验证和验证路线:
Route::group([
'prefix'=>'{locale}',
'where'=>['locale'=>'[a-zA-Z]{2}'],
'middleware'=>'setlocale',
],function(){
Route::get('/login','Auth\LoginController@showLoginForm')->name('login')->middleware('guest');
Route::post('/login','Auth\LoginController@login')->middleware('guest');
Route::post('/logout','Auth\LoginController@logout')->name('logout');
Route::get('register','Auth\RegisterController@showRegistrationForm')->name('register')->middleware('guest');
Route::post('register','Auth\RegisterController@register');
Route::get('/email/verify', 'Auth\VerificationController@show')->name('verification.notice');
}); //closed group locale
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
当我在自己的域电子邮件地址上收到电子邮件时,它有效。
RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
public function redirectTo(){
return route('verification.notice',app()->getLocale());
}
}
在 App\User
中添加一个 routeNotificationForMail()
方法,returns 您希望将电子邮件通知发送到的电子邮件地址。在下面的代码中,我的“电子邮件”字段包含每个用户的电子邮件地址
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
//...
public function routeNotificationForMail($notification)
{
return $this->email;
}
}
托管公司给了我新的不同 MAIL_HOST
现在可以用了,也许旧的被列入黑名单之类的。谢谢大家的评论。
成功注册后,我的应用程序不发送验证电子邮件(它只发送到我域中的电子邮件),我被重定向到 /email/verify,就像它已发送一样(已检查垃圾邮件和促销文件夹)。另一方面,我的忘记密码系统工作得很好,所以我想我的 .env 很好。
这是我的身份验证和验证路线:
Route::group([
'prefix'=>'{locale}',
'where'=>['locale'=>'[a-zA-Z]{2}'],
'middleware'=>'setlocale',
],function(){
Route::get('/login','Auth\LoginController@showLoginForm')->name('login')->middleware('guest');
Route::post('/login','Auth\LoginController@login')->middleware('guest');
Route::post('/logout','Auth\LoginController@logout')->name('logout');
Route::get('register','Auth\RegisterController@showRegistrationForm')->name('register')->middleware('guest');
Route::post('register','Auth\RegisterController@register');
Route::get('/email/verify', 'Auth\VerificationController@show')->name('verification.notice');
}); //closed group locale
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
当我在自己的域电子邮件地址上收到电子邮件时,它有效。
RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
public function redirectTo(){
return route('verification.notice',app()->getLocale());
}
}
在 App\User
中添加一个 routeNotificationForMail()
方法,returns 您希望将电子邮件通知发送到的电子邮件地址。在下面的代码中,我的“电子邮件”字段包含每个用户的电子邮件地址
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
//...
public function routeNotificationForMail($notification)
{
return $this->email;
}
}
托管公司给了我新的不同 MAIL_HOST
现在可以用了,也许旧的被列入黑名单之类的。谢谢大家的评论。