Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 9 - ERROR: The body of "Symfony\Component\Mime\Part\TextPart" must be a string or a resource (got "Illuminate\Http\Response") [duplicate]

after upgrade from Laravel 6 to 9, i have this error...

Below is my code that produce the error:

$pdf = PDF::loadView('general.layouts.pdf.receipt_paid');

$pdf_name = "PAID RECEIPT_123456";
$pdf_stream = $pdf->stream($pdf_name);

Mail::send('general.email.receipt', [], function($message) use($pdf_stream, $pdf_name){
    $message->to("[email protected]")
    ->subject('Your Order (123456) Has Been Paid')
    ->attachData($pdf_stream, $pdf_name, [
        'mime' => 'application/pdf'
    ]);
});

I don't have any idea what is the mistake I made... or do I need to amend something after upgrade to version 9?

I already try use Mailable class instead, but still occurred the same error.

like image 342
Syamsoul Azrien Avatar asked Oct 18 '25 14:10

Syamsoul Azrien


1 Answers

I just solved the problem...

Actually it is not related with Laravel upgrade...

But actually it has problem with barryvdh/laravel-dompdf newer version...

After upgrade laravel-dompdf, I need to use $pdf->output() instead of $pdf->stream($pdf_name)..

Then my problem solved..

The solution is based on this question actually: https://stackoverflow.com/a/60947707/5179633

like image 149
Syamsoul Azrien Avatar answered Oct 21 '25 05:10

Syamsoul Azrien