I have been having an issue with queuing mail. The docs mention having to add illuminate/mail to your composer.json but there are others to add.
My first error was missing SuperClosure. So I had to add jeremeamia/superclosure to my composer.json.
Now I am getting Fatal error: Call to a member function push() on null in C:\xampp\htdocs\vendor\illuminate\mail\Mailer.php on line 182. Someone on IRC thought maybe the illuminate/queue was missing so I tried adding it to composer.json. Nothing was downloaded or updated so It must have been there already.
This is my code
I have been running into this as well. I decided to look into the Mailer file. From a quick var dump, it looks like $this->queue is never set and hence the error.
var_dump($this->queue);
> NULL
Since I never worked on Laravel before (dove straight into Lumen), I am gonna try and reproduce this on former over the weekend.
Ask on the forums please. We only deal with bugs here, not usage problems, sorry.
Add
use \Illuminate\Support\Facades\Queue as Queue;
And change line 182 to
return Queue::push('mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);
this work for me!
Is there a solution for this problem without changing the Mailer Class?
There is nothing in the forum either.
Yes, right there http://lumen.laravel.com/docs/queues
I do not think this is the correct answer.
If there is already a class and a method to treat this does not make sense to rewrite the same thing.
I'll see if someone has other ideas in the forums.
I'm thinking of extending the Mailer class and change the way the Queue is called.
Perhaps one solution would be to check if the Queue is instantiated, if not, when calling a new Queue would be created.
I fixed it just initializing queue.connection before using Mail::queue:
app('queue.connection'); // Just to initialize binding
\Mail::queue(...);
Thanks vedmant. A slight variation using the setQueue method:
$mailer = app('mailer');
$mailer->setQueue(app('queue.connection'));
$mailer->queue(...);
Again a different method:
use Illuminate\Support\Facades\Mail;
...
Mail::setQueue(app('queue.connection'))->queue(...);
@approots @arubacao This is almost a year old, and the app(...) didn't exist at the time I creating this issue.
@carc1n0gen It actually has been there from the very beginning https://github.com/laravel/lumen-framework/commit/cc0287243988a80b0af6703fe8181fe5c43b3e0b#diff-1a29c774763588652842fe842190dccfR32
@vedmant Really? Then it was just not part of the 5.1 docs?
just throwing in my 2 cents for someone else who stumbles upon this too,
use app('queue.connection'); rather than Mail::setQueue() if you are going to be testing the emails or you will run into problems.
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); // or $this->dispatch(new SendEmail);
Mail::queue('email.mytemplate', $data, function ($message) {
$message->from('[email protected]', 'Ishan test mail server');
$message->to('[email protected]')->subject('test subject');
});
}
I'm having an issue with queuing mail in the full Laravel Framework 5.4 (not Lumen), getting:
Method handleQueuedMessage does not exist, when I run php artisan queue:listen.
Stack trace:
#0 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69): Illuminate\Mail\Mailer->__call('handleQueuedMes...', Array)
#1 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69): Illuminate\Mail\Mailer->handleQueuedMessage(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#2 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(317): Illuminate\Queue\Jobs\Job->fire()
#3 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(267): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#4 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(224): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#5 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102): Illuminate\Queue\Worker->runNextJob('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#6 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#7 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#8 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30): call_user_func_array(Array, Array)
#9 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#10 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#11 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Container\Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#12 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Console\Command.php(182): Illuminate\Container\Container->call(Array)
#13 C:\xampp\htdocs\explore\vendor\symfony\console\Command\Command.php(264): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#14 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Console\Command.php(168): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#15 C:\xampp\htdocs\explore\vendor\symfony\console\Application.php(869): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 C:\xampp\htdocs\explore\vendor\symfony\console\Application.php(223): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 C:\xampp\htdocs\explore\vendor\symfony\console\Application.php(130): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 C:\xampp\htdocs\explore\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 C:\xampp\htdocs\explore\artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 {main}
Anyone on this thread have an idea what the issue might be? This is the only google result that I can find that has handleQueuedMessage in the results.
Most helpful comment
I fixed it just initializing queue.connection before using Mail::queue: