Support the ongoing development of Laravel.io →
posted 10 years ago
Mail Queues

Hey guys,

I have a SendEmail command that is dispatched like so:

Bus::dispatch(
        new SendEmail(
            'user@email.com',
            "Test Subject",
            "emails.template",
            $emailData)
    );

I'd like to make it so it ALWAYS just puts this job into the queue so that if I'm not running php artisan queue:listen then the SendEmail command will just sit in the job table not being sent.

I understood this was the default behavior but it seems that if the queue is not running it simply runs the SendEmail command in the current request, thus adding a wait time for the user at this point.

It's entirely possible I've not created the Command correctly so I've included it below just in case. Any pointers would be useful thanks!

class SendEmail extends Command implements SelfHandling, ShouldBeQueued {

    use InteractsWithQueue, SerializesModels;

...

public function handle()
{
        Mail::send($this->template, $this->parameters, function ($message)
        {
            $message->to($this->email, 'User')->subject($this->subject);
        });
}

...
Last updated 3 years ago.
0

Doh. I knew it'd be something simple, I was using the "sync" queue driver! As soon as I changed it over to "database" it worked as expected.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

josborne josborne Joined 7 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.