Laravel邮件无法附加文件

时间:2019-09-13 04:00:21

标签: laravel-5 laravel-mail

电子邮件将发送,但文件将不附加。有什么想法吗?

    public function email_invoice(Request $request, $id){

    $customer = customer::findOrFail($id);

    Mail::send('emails.invoice', ['customer' => $customer], function ($m) use ($customer) {
        $sender_name =  Auth::user()->name;
        $sender_email =  Auth::user()->email;
        $m->from( $sender_email, $sender_name);
        $m->to($customer->email)->subject('Invoice Attached');
        $m->attach('User/myName/invoice.pdf');
    });
}

1 个答案:

答案 0 :(得分:0)

您必须像这样使附加功能用于电子邮件附件

 $m->attach($file->getRealPath(), array(
                    'as' => $file->getClientOriginalName(), // If you want you can chnage original name to custom name      
                    'mime' => $file->getMimeType())
                );