Tuesday, March 7, 2017

Laravel queue mail excel attachement and JSON_ERROR_UTF8

Have a problem while trying to queue mail that have attachment.

I can send an email without any problems without queue. Attachment is correct and can be opened. Problem appear when I try to queue that email. Excel generated by maatwebsite/excel lib

Error:

InvalidPayloadException in Queue.php line 89:
 5

I found that this part of code throws this error:

...\vendor\laravel\framework\src\Illuminate\Queue\Queue.php
protected function createPayload($job, $data = '', $queue = null)
{
    $payload = json_encode($this->createPayloadArray($job, $data, $queue));

    if (JSON_ERROR_NONE !== json_last_error()) {
        throw new InvalidPayloadException;
    }

    return $payload;
}

My code looks like:

excel = Excel::create('Report', function($excel) {
        $excel->sheet('Sheetname', function($sheet) {
            $sheet->fromArray([['aaa']]);
        });
    })->string('xlsx');

    Mail::to('mail@mail.com')
        ->queue(new Report($excel));

I've tried to utf8_encode($excel) but then I cannot open mail attachment and I think that any operation on generated excel will corrupt file...

Any help?



via Grzesiek

Advertisement