2015-12-14 33 views
0

我使用mailgun驅動程序用於發送電子郵件的laravel5發送電子郵件,我與這個代碼努力,如何使用mailgun

foreach ($login_history as $number) 
{ 
$authentication = 
authentication::select('email')->where('phone_no','=',$number)->get(); 
Mail::send('loginreminder.reminder',['number' => $number], 
function($message) use($authentication) { 
$message->to($authentication,'user')->from('no- 
[email protected]','Admin')->subject('Login reminder'); 
}); 
return "success"; 
} 

但我得到下面的錯誤。 SimpleMessage.php中的ErrorException異常第297行:非法偏移類型

回答

0

$authentication是Eloquent集合的一個實例。您必須首先撥打->first()而不是->get()以獲取實際的型號(假設您每個電話號碼只有一個Authentication條目)。然後,訪問該模型上的電子郵件:

foreach ($login_history as $number) 
{ 
    $authentication = authentication::where('phone_no', '=', $number)->first(); 
    Mail::send('loginreminder.reminder', ['number' => $number], function ($message) use ($authentication) 
    { 
     $message->to($authentication->email, 'user')->from('[email protected]', 'Admin') 
       ->subject('Login reminder'); 
    }); 

    return "success"; 
} 
相關問題