【问题标题】:Laravel 7 Mail attachment with excel file using Maatwebsite\Excel 3.1使用 Maatwebsite\Excel 3.1 的 Laravel 7 带有 excel 文件的邮件附件
【发布时间】:2020-08-05 14:03:24
【问题描述】:

我想在我的电子邮件中附加 excel 文件(xlsx 格式)而不在服务器上保存文件。 我已经有一个可供下载的工作代码。 以下是我正在尝试做的事情并遇到错误。


代码

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


错误

无法打开文件进行读取 [HTTP/1.0 200 OK 缓存控制:公共 内容处置:附件;文件名=Order-4.xlsx 日期:格林威治标准时间 2020 年 8 月 5 日星期三 13:55:24 最后修改时间:格林威治标准时间 2020 年 8 月 5 日星期三 13:55:24]

我正在使用 Laravel 7.x 和 Maatwebsite\Excel 3.1

【问题讨论】:

    标签: laravel


    【解决方案1】:

    我用下面的代码修复了它

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

    【讨论】:

      猜你喜欢
      • 2021-07-26
      • 2019-05-20
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      相关资源
      最近更新 更多