How to attach a PDF using barryvdh/laravel-dompdf into an email in Laravel

£可爱£侵袭症+ 提交于 2019-12-10 12:47:29

问题


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 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!';
  }

回答1:


Use $message->attachData($pdf->output(), 'filename.pdf'); instead of $message->attach($pdf->output());.



来源:https://stackoverflow.com/questions/40847992/how-to-attach-a-pdf-using-barryvdh-laravel-dompdf-into-an-email-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!