2017-04-07 59 views
0

你好,我嘗試從一個命令一個excel文件發送一封電子郵件,但它似乎不起作用郵件梅索德

我得到這個例外,當我嘗試運行工匠命令:

調用未定義的方法照亮\郵件\ PendingMail ::主題()

現在有人如何解決這個問題呢?感謝很多提前

這裏我的命令:

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('[email protected]') 
      ->attach($excel_file , 'LaFontDaily.xls') 
      ->send(); 

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

哪個laravel版本? – dparoli

+0

我使用L 5.4! –

+0

您的郵件門面的使用不正確,請檢查文檔發送電子郵件原料:https://laravel.com/docs/5.1/mail#sending-mail – dparoli

回答

0

嘗試使用郵件是這樣的:

Mail::raw('Text to e-mail', function ($m) use ($user, $excel_file) { 
    $m->to($user->email); 
    $m->subject('Licences Lafont Daily'); 
    $m->from('[email protected]'); 
    $m->attachData($excel_file->string() , 'LaFontDaily.xls'); 
}); 

來源:laravel 5.1 docs,在很大程度上仍然有效爲5.4

不知道$ excel_file是內存中的數據,因此它的,如果你之前保存的文件,並調用更好:

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

旁註:Auth::user()應該在命令返回任何所以它是更好,如果你在到()函數使用預定義的電子郵件地址。

+0

也不能訪問$用戶也! –

+0

我更新$用戶訪問代碼 – dparoli

+0

我得到嘗試的命令來獲取非對象 –