在laravel 5.7中以电子邮件附件形式发送pdf文件

在laravel 5.7中以电子邮件附件形式发送pdf文件,laravel,Laravel,我想以pdf格式发送发票刀片文件的电子邮件,但我收到以下错误 (1/1)Swift_IOU例外 无法打开文件进行读取[/storage/D:\xampp\htdocs\clientreq\public/mypdf.pdf] 控制器: public function insert(Request $req) { ini_set('max_execution_time', 300000); $mytime = Carbon::now(); $project_ty

我想以pdf格式发送发票刀片文件的电子邮件,但我收到以下错误

(1/1)Swift_IOU例外 无法打开文件进行读取[/storage/D:\xampp\htdocs\clientreq\public/mypdf.pdf]

控制器:

 public function insert(Request $req)
    {
      ini_set('max_execution_time', 300000);
    $mytime = Carbon::now();
    $project_type=implode(',',$req->input('project_type'));
    //$qty=implode(',',$req->input('qty'));
    $amount=implode(',',$req->input('amount'));
    $id=$req->input('id');
    $bill_date=$req->input('bill_date');
    $updated_at=$mytime->toDateTimeString();
      $created_at=$mytime->toDateTimeString();
      $data = array('client_id'=>$id,'date_of_bill'=>$bill_date,'description'=>$project_type,'amount'=>$amount,'created_at' => $created_at,'updated_at' => $updated_at);
    DB::table('bill')->insert($data);

    $client = DB::table('requirement')
                  ->join('bill','requirement.id','=','bill.client_id')
                  ->select('requirement.*','bill.*')
                  ->where('requirement.id',$id)
                  ->where('bill.date_of_bill',$bill_date)
                  ->first();

    $data = array(
            'client_name' => $client->client_name,
            'company_name' => $client->company_name,

        );

    $pdf = \PDF::loadView('pages.invoice',$data);
    //return $pdf->stream();

    $data = array(
        'email_address'=>'seemashelar01@gmail.com',

    );

    Mail::send('pages.invoice', $data, function($message) use($data) {
    $message->from('seemashelar01@gmail.com', 'PuraBox');
    $message->to($data['email_address']);
    $message->subject('hello');
    $filename = \Storage::url(public_path() . '/' . 'mypdf.pdf');
    $message->attach($filename);
    //Full path with the pdf name

});  

    }

如果您想从
存储器
获取地址文件,应调用
attachFromStorage
,如下所示:

    $message->attachFromStorage(
           /path/to/file',
           'name.pdf', [
               'mime' => 'application/pdf'
           ]);

更多信息:

如果您想从
存储器中获取地址文件
您应该调用
附件存储
,如下所示:

    $message->attachFromStorage(
           /path/to/file',
           'name.pdf', [
               'mime' => 'application/pdf'
           ]);
更多信息:

试试下面的例子

试试下面这个例子


您的文件路径不正确,您的pdf位于公共路径或存储中您的文件路径不正确,您的pdf位于公共路径或存储中(1/1)ErrorException call\u user\u func\u array()期望参数1为有效回调,类“Swift\u Message”没有方法“attachFromStorage”此错误累计(1/1)ErrorException call\u user\u func\u array()要求参数1为有效回调,类“Swift\u Message”没有方法“attachFromStorage”此错误accur(1/1)异常框属性计算需要包含块宽度此错误发生我希望使用电子邮件$file=Config::get('invoice.path')将创建的发票发送给用户/39/公司/1/发票/'。'发票编号为“27”。pdf'$消息->附加($file,array('as'=>'invoice','mime'=>'application/pdf');尝试上面的示例(1/1)异常框属性计算要求包含块宽度发生此错误我希望使用电子邮件$file=Config::get('invoice.path')将创建的发票发送给用户/39/公司/1/发票/'。'发票编号为“27”。pdf'$消息->附加($file,array('as'=>'invoice','mime'=>'application/pdf');试试上面的例子