rlacerda83's avatar

Mail Queue Problem Illuminate\Mail with Lumen

Hello,

I got fatal error: Call to a member function push() when run:

Mail::queue('email.blank', ['html' => $html], function($msg) {
            $msg->to(['email@gmail.com']);
            $msg->from(['email@gmail.com']);
            $msg->subject('Lumen Service Mail');
        });

Its work if change file: Illuminate\Mail\Mailer.php

Add use \Illuminate\Support\Facades\Queue as Queue;

And change line 205:

from: return $this->queue->push('mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);

to return Queue::push('mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);

this work for me!!

I opened a issue in github, but I was informed that this is a problem in using the tool, and is not a bug.

This is the issue link: https://github.com/laravel/framework/issues/10083#event-395963283

Any sugestion for handle this without change the mailer class?

0 likes
4 replies
ktquez's avatar

In Lumen needed package "jeremeamia/SuperClosure" and add on top:

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Bus\SelfHandling;

class nameClass implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;
rlacerda83's avatar

I have the package installed.

The problem is not with the Queue, but the use of Queue with Mailer class.

privatebox's avatar

Create a new job - use the follwoing sample code


namespace App\Jobs;
use App\Jobs\Job;

class SendEmail extends Job { /** * Create a new job instance. * * @return void */ public function __construct() { // }

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    //
}

}

and in your controller

include the SendMail under the namepsace;


use App\Jobs\SendEmail;

mail sending method

public function mailSend()
{
        $data = array(
            'title' => 'test title',
            'description' => 'test description',
        );
        Queue::push(new SendEmail);
    Mail::queue('email.mytemplate', $data, function ($message) {
        $message->from('[email protected]', 'Ishan test mail server');
        $message->to('[email protected]')->subject('test subject');
    });

}

Please or to participate in this conversation.