问题
I've upgraded my laravel instance from version 5.6 to version 5.7. Now I try to use the built-in email verification from laravel.
My problem is that I don't get an email after successful registration when I use the "resend" function the email arrives.
What is the problem?
回答1:
I had this exactly same problem. That is default code from Laravel.
In order to send the email after successful registration you can do this workaround:
at App\Http\Controllers\Auth\RegisterController
change this:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
to this:
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$user->sendEmailVerificationNotification();
return $user;
}
回答2:
I also have had the same issue. As I checked the source code, it isn't necessary to implement to call the sendEmailVerificationNotfication() method, you just should add the event handler to your EventServiceProvider.php, as because of your event handler was previously created, so Larael can't update that. It should look like this:
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
回答3:
In addition to djug's reply, if you experience the same problem after upgrading from version 5.6, just as I did, you'll find step-by-step guide what to implement here:
https://laravel.com/docs/5.7/upgrade
under the section Email Verification
Hope this helps someone as I was struggling quite some time with this.
回答4:
If you have a custom registration page, you could just fire the event after you have created the user like so:
event(new Registered($user));
回答5:
in case somebody else is looking for a solution for the same problem.
please read the documentation, it explains exactly what needs to be done to solve this issue
https://laravel.com/docs/5.7/verification
in a nutshell, and if you are already using 5.7 (i.e you have the necessary fields in your users table) all that you need to do is the following:
- make your
Usermodel implement theMustVerifyEmailinterface. - add
['verify' => true]to theAuth::routesmethodAuth::routes(['verify' => true]);
you can find everything you need about email verification in the link above.
来源:https://stackoverflow.com/questions/52569442/laravel-5-7-verification-email-is-not-sent