0
votes

I want to attached excel file (xlsx format) in my email without saving file on the server. I already have a working code for download. Following is what i am trying to do and getting error.


Code

$excelFile = Excel::download(new OrderExport($this->order), 'Order-'. $this->order->id . '.xlsx'); $mail->attach($excelFile, ['as' => 'Order-'. $this->order->id . '.xlsx']);


Error

Unable to open file for reading [HTTP/1.0 200 OK Cache-Control: public Content-Disposition: attachment; filename=Order-4.xlsx Date: Wed, 05 Aug 2020 13:55:24 GMT Last-Modified: Wed, 05 Aug 2020 13:55:24 GMT]

I am using Laravel 7.x and Maatwebsite\Excel 3.1

1

1 Answers

1
votes

I got it fixed with the following code

$excelFile = Excel::raw(new OrderExport($this->order), \Maatwebsite\Excel\Excel::XLSX); $mail->attachData($excelFile, 'Order-'. $this->order->id . '.xlsx');