如何使用 barryvdh/laravel-dompdf 将 PDF 附加到 Laravel 中的电子邮件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40847992/
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
How to attach a PDF using barryvdh/laravel-dompdf into an email in Laravel
提问by mcornille
I know this question has been asked before but I apparently need my hand held. I'm trying to attach the pdf to an email and send it off. I've done it outside of Laravel with PHPMailer, but now I'm trying to it the Laravel way and cant get it to work. What am I doing wrong here?
我知道以前有人问过这个问题,但我显然需要我的手。我正在尝试将 pdf 附加到电子邮件并将其发送出去。我已经在 Laravel 之外使用 PHPMailer 完成了它,但是现在我正在尝试以 Laravel 的方式来完成它并且无法让它工作。我在这里做错了什么?
Here is the start of the error I'm getting :
这是我收到的错误的开始:
Swift_IoException in FileByteStream.php line 144: Unable to open file for reading [%PDF-1.3
FileByteStream.php 第 144 行中的 Swift_IoException:无法打开文件进行读取 [%PDF-1.3
public function attach_email($id){
$info = Load::find($id);
$info = ['info'=>$info];
Mail::send(['text'=>'mail'], $info, function($message){
$pdf = PDF::loadView('pdf.invoice');
$message->to('[email protected]','John Smith')->subject('Send Mail from Laravel');
$message->from('[email protected]','The Sender');
$message->attach($pdf->output());
});
echo 'Email was sent!';
}
回答by pinepain
Use $message->attachData($pdf->output(), 'filename.pdf');
instead of $message->attach($pdf->output());
.
使用$message->attachData($pdf->output(), 'filename.pdf');
代替$message->attach($pdf->output());
。