Laravel cronjob任务命令中的邮件方法

Laravel cronjob任务命令中的邮件方法,laravel,laravel-5.4,Laravel,Laravel 5.4,你好,我试图通过命令发送一封包含excel文件的电子邮件,但似乎不起作用 我在尝试运行artisan命令时遇到此异常: public function handle() { $user = Auth::user(); $licencies = Licencies::where('lb_assurance' , '=' , 'Lafont') ->where('created_at' , Carbon::today())->get();

你好,我试图通过命令发送一封包含excel文件的电子邮件,但似乎不起作用

我在尝试运行artisan命令时遇到此异常:

 public function handle()
 {
     $user = Auth::user();

     $licencies = Licencies::where('lb_assurance' , '=' , 'Lafont')
         ->where('created_at' , Carbon::today())->get();

     $excel_file = Excel::create('DailyRecapLicencesLafont', 
         function($excel) use ($licencies) {
             $excel->sheet('Excel', function($sheet) use ($licencies) {
                $sheet->fromArray($licencies);
             });
          });

        Mail::to($user)
            ->subject('Licences Lafont Daily')
            ->from('test@test.fr')
            ->attach($excel_file , 'LaFontDaily.xls')
            ->send();

        $this->info('Lafont task Done');
    }
调用未定义的方法Illumb\Mail\PendingMail::subject()

有人现在怎么解决这个问题?提前多谢

这是我的命令:

 public function handle()
 {
     $user = Auth::user();

     $licencies = Licencies::where('lb_assurance' , '=' , 'Lafont')
         ->where('created_at' , Carbon::today())->get();

     $excel_file = Excel::create('DailyRecapLicencesLafont', 
         function($excel) use ($licencies) {
             $excel->sheet('Excel', function($sheet) use ($licencies) {
                $sheet->fromArray($licencies);
             });
          });

        Mail::to($user)
            ->subject('Licences Lafont Daily')
            ->from('test@test.fr')
            ->attach($excel_file , 'LaFontDaily.xls')
            ->send();

        $this->info('Lafont task Done');
    }

试着像这样使用邮件:

Mail::raw('Text to e-mail', function ($m) use ($user, $excel_file) {
    $m->to($user->email);
    $m->subject('Licences Lafont Daily');
    $m->from('test@test.fr');
    $m->attachData($excel_file->string() , 'LaFontDaily.xls');
});
来源:,在很大程度上仍然适用于5.4

不确定$excel_文件是否为内存中的数据,因此最好先保存该文件,然后调用:

 $m->attach($path_to_file , 'LaFontDaily.xls');

旁注:
Auth::user()
在命令中不应返回任何内容,因此最好在to()函数中使用预定义的电子邮件地址。

哪个laravel版本?我使用L 5.4!!!您的邮件外观用法不正确,请检查发送原始电子邮件的文档:我创建了一个带有标记的邮件方法我尝试了以下方法:公共函数handle(){$user=Auth::user();$licensions=licensions::where('lb_assurance','=','Lafont')->where('created_at',Carbon::today())->get();Mail::to($user)->send(new-licenselafont($licensions));$this->info('Lafont task Done');}但它告诉我,传递给App\Mail\licenselafont::\uu construct()的参数1不能是App\licensions的实例,给定的light\Database\elounce\Collection的实例,请允许我解释一下,对于那些现在不使用laravel 5.4的用户,我所做的事情的最佳方式是什么。也不能访问$user!我在命令的答案Auth::user()中添加了非object的get-try-get属性,该属性返回null,因此$user为null