Ad

Send Email From Queued Event Handler

I use Lumen 5.1 and Redis for queues. And I 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?

Ad

Answer

It was not a bug, just an unexpected behaviour.

I am using Xampp on Windows and the php mail driver for development. For some reason the queued mails were not saved in the default mailoutput folder within the Xampp directory. Instead a new mailoutput folder was automatically created within the Lumen directory.

There I found all the missed mails. :)

Ad
source: stackoverflow.com
Ad