如何使用barryvdh/laravel-dompdf将PDF附加到Laravel中的电子邮件中 [英] How to attach a PDF using barryvdh/laravel-dompdf into an email in Laravel
问题描述
我知道这个问题以前曾被问过,但我显然需要手持.我正在尝试将pdf附加到电子邮件并将其发送出去.我已经使用PHPMailer在Laravel之外完成了它,但是现在我正在尝试以Laravel的方式进行操作,并且无法使其正常工作.我在这里做什么错了?
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?
这是我遇到的错误的开始:
Here is the start of the error I'm getting :
Swift_IoException: 无法打开文件以阅读[%PDF-1.3
Swift_IoException in FileByteStream.php line 144: Unable to open file for reading [%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('example@gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from@gmail.com','The Sender');
$message->attach($pdf->output());
});
echo 'Email was sent!';
}
推荐答案
使用$message->attachData($pdf->output(), 'filename.pdf');
代替$message->attach($pdf->output());
.
这篇关于如何使用barryvdh/laravel-dompdf将PDF附加到Laravel中的电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!