pordonez
2 weeks ago

Laravel add attachment file from public folder to email

Posted 2 weeks ago by pordonez

i tried to attach a file on my email function with this code

$data = array();
        $mail = Mail::send('email.orderForm', $data, function($message) {

            $id = request('order_id');
            $email = request('email');
            
            $corel = UploadFiles::where('order_no', $id)->where('type', 'corel')->orderBy('id', 'desc')->first();
            $pdf = UploadFiles::where('order_no', $id)->where('type', 'pdf')->orderBy('id', 'desc')->first();

            $corelPath = public_path() . '/' . $id . '/' . $corel->file;
            $pdfPath = public_path() . '/' . $id . '/' . $pdf->file;
            // dd($corelPath);
            // dd($pdfPath);

            $subj = $email .' has finished the order forms';
            $sendto = $email;

            $message->to($sendto, $subj)->subject($subj);
            $message->from('[email protected]', 'Developer');
            $message->attach($corelPath);
            
        });

and i received it with no attachment but weird texts.

Please sign in or create an account to participate in this conversation.