简体   繁体   English

Laravel 5邮件队列不起作用

[英]Laravel 5 Mail Queue is Not Working

I am trying to queue emails in Laravel 5.2 but I keep getting empty payloads in the database (As Below) 我试图在Laravel 5.2中排队电子邮件,但我一直在数据库中获得空的有效负载(如下)

空有效负载

My config\\queue.php 我的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. 我也试过Mail::later()没有成功。

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). 显然,序列化程序不喜欢字节字符串(在这种情况下为$ admin_pdf)。

You can fix it by base64_encoding the byte-string data before queueing it, then decoding it again in the closure like this: 您可以在排队之前通过base64_encoding字节串数据来修复它,然后在闭包中再次解码它,如下所示:

$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');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM