I am trying to queue emails in Laravel 5.2 but I keep getting empty payloads in the database (As Below)
My config\queue.php
'connections' => [
...
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
...
]
My code for Queuing:
if(Input::get('email-admin')) {
$admin_pdf = PDF::loadView('emails.reporting.checkin-report', ['content' => $admin_email])->inline();
Mail::queue('emails.reporting.checkin-email', [], function ($m) use ($admin_pdf, $start) {
//Admin should have User ID of '1'
$admin = User::find(1);
$report_name = $start->format('F') . '-report.pdf';
$m->attachData($admin_pdf, $report_name);
$m->to($admin->email, $admin->first_name)->subject('flexxifit ' . $start->format('F') . ' Report');
});
}
I have also tried Mail::later()
with no success.
Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQS, Redis, or even a relational database. Laravel's queue configuration options are stored in your application's config/queue.php configuration file.
You should run the listener in console:
php artisan queue:listen
Read more here
Apparently, the serializer does not like byte-strings ($admin_pdf in this case).
You can fix it by base64_encoding the byte-string data before queueing it, then decoding it again in the closure like this:
$adminPdf = base64_encode($pdfData); //Encoded here
Mail::queue('emails.reporting.admin-report', $emailData, function (Message $m) use ($adminPdf) {
$m->attachData(base64_decode($adminPdf), $reportName); //Decoded here
$m->to($adminEmail)->subject('Admin Report');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With