mercredi 30 décembre 2015

Send email from queued event

I use Lumen 5.1 and have a pretty standard event handler that should send an email:

<?php

namespace App\Handlers\Events;

use Illuminate\Contracts\Queue\ShouldQueue;
use App\Events\UserHasRegistered;
use Illuminate\Contracts\Mail\Mailer;

class SendWelcomeEmail implements ShouldQueue
{
    protected $mailer;

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    public function handle(UserHasRegistered $event)
    {
        $user = $event->user;

        $this->mailer->raw('Test Mail', function ($m) use ($user) {
            $name = $user->getFirstName().''.$user->getLastName();

            $m->to($user->auth()->getEmail(), $name)->subject('This is a test.');
        });
    }
}

The email is sent when I don't use the ShouldQueue interface. But when I push the event handler to the queue (i. e. use the ShouldQueue interface), the email is not sent and I don't get any error messages.

Do you have any ideas how to solve or debug this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire