简体   繁体   中英

Laravel email queue works but doesn't send

I'm having a problem where i'm trying to queue a message to send to the registered user, when i am running everything works, but the queue just wont work, can someone help me with this please? Here's the registration controller

 protected function create(array $data)
    {
      $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'type' => $data['type'],
        ]);
        $email = (string)$data['email'];
        $job = (new SendEmailJob($email))->delay(Carbon::now()->addSeconds(5));
        dispatch($job);

        return $user;
    }

I have checked if i can send email and it works i can send email but when i am pointing to a specific email rather to the data which came from the register form. Here's the SendEmailJob

 public function handle($user)
    {
        Mail::to($user)->send(new SendEmailMailable());
    }

It sounds like you don't have a queue running. You can do this with

php artisan queue:work

It's also possible you will want a failed jobs table and artisan has a command for that:

php artisan queue:failed-table

php artisan migrate

If you want to delete all your failed jobs you can do this:

php artisan queue:flush

And I recommend reading up on all this on the laravel docs site: https://laravel.com/docs/5.7/queues

And I also want to share a good post on stackoverflow regarding queues .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM