Search code examples
laraveldompdf

Laravel Dompdf attachment coming Unable to JSON encode payload. Error code: 5


I have written below code in Mail/Mails.php file build function.

return $this->from(config('app.FROM_EMAIL'),config('app.MAIL_FROM_NAME'))
                    ->subject($this->subject)
                    ->view('emails.generalmail')
                    ->attachData($this->attach,'file_pdf.pdf');

Error

Unable to JSON encode payload. Error code: 5

I used Dompdf email send with attachment.


Solution

  • I'm not sure what version of Laravel you are on so it could be slightly different but you need to use the attach function rather than attachData

    return $this->from(config('app.FROM_EMAIL'),config('app.MAIL_FROM_NAME'))
                        ->subject($this->subject)
                        ->view('emails.generalmail')
                        ->attach('[PATH TO FILE]');
    

    See more here: Laravel Mail Docs

    Change the version at the top.