我使用PHP Laravel v5.0。我想發送電子郵件給divisi = X的所有用戶。$ penerima的查詢顯示了3封電子郵件,其中divisi = X.但是電子郵件剛剛發送到1封電子郵件中的3封電子郵件。你知道我的代碼有哪個錯誤嗎?感謝如何發送電子郵件給所有使用php laravel的條件的用戶?
if ($approve != null){
foreach ($approve as $X) {
$penerima = User::select('email')
->where('divisi','=', $X)
->where('deleted','=', '0')
->get();
Mail::send('mail', $data_nomor, function ($m) use ($penerima) {
$m->to($penerima)->subject('Respond Reminder!');
});
}
}
如果我顯示的$ penerima結果,結果是
照亮\數據庫\雄辯\集合對象([項目:保護] =>陣列([0] => App \ User Object([table:protected] => users [hidden:protected] => Array([0] => password [1] => remember_token)[connection:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array([email] => [email protected])[original:protected] => Array([ email] => [email protected])[relations:protected] => Array()[visible:protected] => Array()[appends:protected] => Array() Array()[guarded:protected] => Array([0] => *)[dates:protected] => Array()[casts:protected] => Array()[touches:protected ] => Array()[observables:protected] => Array()[with:protected] => Array()[morphClass:protected] => [exists] => 1)[1] => App \ User Object [table:protected] => users [hidden:protected] => Array([0] => password [1] => remember_token)[connection:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array([email] => [email protected])[original:protected] => Array([email] => hsaput208 Array()[appends:protected] => Array()[fillable:protected] => Array()[guarded:protected] = Array()[touches:protected] => Array()[observables:protected] => Array([] => *)[日期:保護] => Array()[casts: )[with:protected] => Array()[morphClass:保存] => [exists] => 1)[2] => App \ User Object([table:protected] => users [hidden:protected] => Array([0] => password [1] => remember_token )[連接:保護] => [primaryKey:保護] =>身份證[每頁:保護] => 15 [遞增] => 1 [時間戳] => 1 [屬性:保護] =>陣列([電子郵件] =>數組([email:] = [email protected])[relations:protected] => Array()[visible:protected] => Array()[appends:protected ] => Array()[fillable:protected] => Array()[guarded:protected] => Array([0] => *)[dates:protected] => Array()[casts:protected] => Array ()[touches:protected] => Array()[observables:protected] => Array()[with:protected] => Array()[morphClass:protected] => [exists] => 1)))
如果我將get()更改爲pluck('email'),結果就是
首先獲得所有電子郵件,然後在'foreach'循環發送電子郵件。現在,您在foreach循環中從查詢中獲取電子郵件,然後將郵件發送到第一個郵件。它也應該是'$ penerima = User :: select('email') - >其中(...' –