小编mco*_*lle的帖子

如何使用barryvdh/laravel-dompdf将PDF附加到Laravel中的电子邮件中

我知道之前已经问过这个问题,但我显然需要我的手持.我正在尝试将pdf附加到电子邮件中并将其发送出去.我已经使用PHPMailer在Laravel之外完成了它,但现在我正在尝试使用Laravel方式并且无法使其工作.我在这做错了什么?

这是我得到的错误的开始:

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('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!';
  }
Run Code Online (Sandbox Code Playgroud)

php pdf email attachment laravel

9
推荐指数
1
解决办法
5341
查看次数

如何将 Excel 文件附加到电子邮件中?

我想我很接近,我只需要在 Mail 中传递 $excelFile 但它一直说它未定义,但是当我传递 $truckstop_post 时它会通过,但数据格式不正确,因为它还没有通过 Excel::create 。如何将 \Excel::create 的结果获取到 Mail::send 中?

public function truckstopPost()
{   
    $type = 'csv';



    $truckstop_post = Loadlist::select('pick_city', 'pick_state', 'delivery_city', 'delivery_state', 'trailer_type', 'pick_date', 'load_type', 'length', 'width', 'height', 'weight', 'offer_money', 'special_instructions', 'company_contact', 'contact_phone')->where('urgency', 'OPEN')->orderBy('id', 'desc')->get();

    $excelFile = \Excel::create('itransys', function($excel) use ($truckstop_post) {
        $excel->sheet('mySheet', function($sheet) use ($truckstop_post)
        {
            $sheet->fromArray($truckstop_post);

        });


       $info = Load::find(8500);

       $info = ['info'=>$info];


       Mail::send(['html'=>'email.invoice_email_body'], $info, function($message) use ($info, $excelFile){

        $message->to('mike@gmail.com')->subject('subject');

        $message->from('mike@gmail.com', \Auth::user()->name);

        $message->attachData($excelFile, 'Invoice.csv');

        });


        });

    return back()->with('status', 'You Posted Truckstop!');

}
Run Code Online (Sandbox Code Playgroud)

如果我将 $truckstop_post …

php email-attachments laravel maatwebsite-excel

7
推荐指数
2
解决办法
1万
查看次数