samedi 25 avril 2020

Send CSV file as Email attachement in Laravel

I am working on Laravel file attachment. I have successfully generated a .pdf file and sent as attachment in mail. Now I have to send CSV file as attachment in mail with Laravel. When I click the submit button it just download the file rather then to send an email.

Controller Code:

$data["email"] = $request->recipient_email;
$data["subject"] = 'Cashup Report for '. $venue->name;
$data["bodyMessage"] = $venue->name.' from '.$start.' to '.$end ;

 $excel = Excel::create(uniqid().'Cashups', function($excel) use($transactions,$start,$end,$venue) {
                        $excel->sheet('New sheet', function($sheet) use($transactions,$start,$end,$venue) {
      $sheet->loadView('excel.cashups', array('transactions' => $transactions, 'start'=> $start, 'end' => $end, 'venue' => $venue));
            });
 });

     //Feedback mail to client
 Mail::send('emails.cashups_report', $data, function($message) use ($data,$excel){
    $message->from(config('mail.from.address'));
    $message->to($data["email"]);
    $message->subject($data["subject"]);
    //Attach PDF doc
    $message->attachData($excel->output(),'cashups-report.xlsx');
});

I dont know where i am going wrong. I would appreciate if someOne Guide me through this. Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2VCcyBD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire