PDF 作为邮件附件 - Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31005052/
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 11:49:34  来源:igfitidea点击:

PDF as mail attachment - Laravel

laravelpdfsendmail

提问by Keith666

I want to create a PDF using the barryvdh/laravel-dompdf package and send this with an email as attachment.

我想使用 barryvdh/laravel-dompdf 包创建一个 PDF,并通过电子邮件作为附件发送。

The code I have now is:

我现在的代码是:

$pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur));

Mail::queue('emails.factuur', array('factuur' => $factuur), function($message) use ($pdf)
   {
       $message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp');
       $message->attach($pdf->output());
    });

But now I get the following error:

但现在我收到以下错误:

Serialization of 'Closure' is not allowed

回答by Luceos

You can only send serializable entities to the queue. This includes Eloquent models etc. But not the PDF view instance. So you will probably need to do the following:

您只能将可序列化的实体发送到队列。这包括 Eloquent 模型等。但不包括 PDF 视图实例。因此,您可能需要执行以下操作:

Mail::queue('emails.factuur', array('factuur' => $factuur), function($message)
   {
       $pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur));
       $message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp');
       $message->attach($pdf->output());
    });