Laravel 5.7 - Verification email is not sent
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;
}
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,
],
];
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
User
model implement theMustVerifyEmail
interface. - add
['verify' => true]
to theAuth::routes
methodAuth::routes(['verify' => true]);
you can find everything you need about email verification in the link above.