Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.7 - Verification email is not sent

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?

like image 868
Markus Avatar asked Sep 29 '18 14:09

Markus


2 Answers

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;
    }
like image 127
JMoura Avatar answered Dec 05 '22 01:12

JMoura


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,
        ],
    ];
like image 24
laze Avatar answered Dec 05 '22 01:12

laze