【问题标题】:Attach PDF file into a Mail将 PDF 文件附加到邮件中
【发布时间】:2017-09-17 02:12:07
【问题描述】:

我尝试从希望在 PDF 中工作的视图中附加一个 pdf 文件。但是当我尝试将此作为 PDF 文件附加到电子邮件中时,我得到了

FileByteStream.php 第 144 行中的 Swift_IoException:无法打开文件 用于阅读 [HTTP/1.0 200 OK Cache-Control: no-cache, private 内容处置:附件;文件名="invoice.pdf" 内容类型: 申请/pdf

有人知道我在哪里做错了吗?提前非常感谢

这里是我的控制器:

公共函数构建() {

    $federation = Structure::where('id' , '1')->first();
    $structure = Structure::where(['id' => $this->order->structure_id])->first();
    $order = $this->order;

    $url = url('/cotisationstructure/'.$this->order->id);

    $pdf = app('dompdf.wrapper');
    $pdf->loadView('cotisation_structure.facturePDFsingle', compact('order' , 'structure' , 'federation'));

    return $this->markdown('email.commande' ,compact('federation' , 'structure' , 'url'))
        ->subject('Nouvelle Achat de Licences sur FFRXIII Licences & Compétitions')
        ->attach($pdf->download('invoice.pdf'));
}

【问题讨论】:

  • 你在使用 barryvdh/laravel-dompdf 吗?
  • 是的,我使用 dompdf

标签: laravel


【解决方案1】:

您需要在附加功能中将文件名指定为string。如需更多信息,请点击此处:https://laravel.com/docs/5.4/mail#attachments

【讨论】:

  • 现在使用:->attachData($pdf->output(), ''.$this->order->num_facture.'.pdf');
  • 您还应该在第三个参数中指定 mime 类型:->attachData($pdf->output(), ''.$this->order->num_facture.'.pdf', [ 'mime' => '应用程序/pdf'])
猜你喜欢
  • 1970-01-01
  • 2020-11-21
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-01
  • 2016-01-18
  • 2023-03-07
相关资源
最近更新 更多