【发布时间】:2017-01-20 16:42:40
【问题描述】:
我想我很接近,我只需要在 Mail 中传递 $excelFile,但它一直说它未定义,但是当我传递 $truckstop_post 时它会通过,但数据的格式不正确,因为它没有通过 Excel::创建呢。如何将 \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!');
}
如果我将 $truckstop_post 传递给 attachData(),这就是结果的样子,但这当然不是格式良好的 csv 文件
【问题讨论】:
-
到底是什么问题?生成excel?将其附加到电子邮件中?
-
如何将其附加到电子邮件中,$message->attachData(???, 'Invoice.csv');那么 ->download($type); 会发生什么?
-
所以从问题中删除与文件附件无关的所有内容。假设您有文件 X 并且想要附加它。
-
他没有文件 X。他只是在飞行中创建文件并返回路线。那是他的问题。他没有存储文件
-
@Paras 所以问题应该是“如何将路由中的数据存储为文件?”这就是为什么我问到底是什么问题。
标签: php laravel email-attachments maatwebsite-excel