如何使用mailgun在laravel5中发送电子邮件

时间:2015-12-14 13:30:57

标签: laravel-5

我正在使用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-
reply@xyz.co','Admin')->subject('Login reminder');
});
return "success";
}

但我收到以下错误。 SimpleMessage.php第297行中的ErrorException:非法偏移类型

1 个答案:

答案 0 :(得分:0)

$authentication是Eloquent Collection的一个实例。您首先必须致电->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( 'no-reply@xyz.co', 'Admin' )
                ->subject( 'Login reminder' );
    } );

    return "success";
}
相关问题