Reputation: 313
I have a problem here.. i try to send email to multiple recepients. The recepients are from my database which name of table is subscribes the message error is like this
ErrorException in SimpleMessage.php line 297: Illegal offset type
public function store_job(Request $request)
{
$this->validate($request, ['posisi' => 'required','persyaratan' => 'required','tanggung_jawab' => 'required']);
$tambah = new jobs(); //kita buat objek yang terhubung ke table JOBS
$tambah->posisi = $request['posisi'];
$tambah->persyaratan = $request['persyaratan'];
$tambah->tanggung_jawab = $request['tanggung_jawab'];
$tambah->kategori = $request['kategori'];
$tambah->save();
$anu = DB::table('subscribes')->select('email');
$data = array ('email'=>$anu);
Mail::send('emails.news', $data, function ($message) use ($request, $data) {
$message->from('[email protected]',$request->email);
$message->to($data['email'])->subject($request->posisi);;
});
return redirect()->to('/panel_admin/opportune');
}
please help as fast as possibble.. because i am a student, this is my homework for examination.
Upvotes: 0
Views: 568
Reputation: 2736
Here what I'am doing is declaring a new array $emails
to store all email from database. By iterating the retrieved object anu
, I am pushing the email to $emails
and passing it to the to
property of the mail.
$anu = DB::table('subscribes')->select('email')->get();
$emails=[];
foreach($anu as $a){
$emails[]=$a->email;
}
Mail::send('emails.news', $emails, function ($message) use ($request, $emails) {
$message->from('[email protected]',$request->email);
$message->to($emails)->subject($request->posisi);;
});
Upvotes: 1
Reputation: 20289
Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.
This question should about match your effort.
Upvotes: 0