laravel 将 PDF 文件附加到邮件中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43519592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:49:38  来源:igfitidea点击:

Attach PDF file into a Mail

laravel

提问by Mathieu Mourareau

I try to attach a pdf file from a view wish is working in PDF. but when i try to attach this as a PDF file into an email , i get

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

Swift_IoException in FileByteStream.php line 144: Unable to open file for reading [HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Disposition: attachment; filename="invoice.pdf" Content-Type: application/pdf

FileByteStream.php 第 144 行中的 Swift_IoException:无法打开文件进行读取 [HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Disposition: attachment; filename="invoice.pdf" 内容类型:应用程序/pdf

Someone know where i am doing it wrong ? thanks a lot in advance

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

Here my controller :

这是我的控制器:

public function build() {

公共函数构建(){

    $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'));
}

采纳答案by Pankit Gami

You need to give filename as stringin attach function. For more check here : https://laravel.com/docs/5.4/mail#attachments

您需要string在附加功能中提供文件名。更多信息请查看:https: //laravel.com/docs/5.4/mail#attachments