i got this error when i’m trying to send multiple email, and i also want to pass a data to mail view.
here is my controller:
$get_no_inven = Permohonan::find($id_per)->no_inventaris; $get_users = DB::table('users')->where('hak_akses','=','deputi')->get(['email']); $recipients = [ $get_users ]; $subject = 'Testing email no 2'; $meta = 'meta'; foreach($recipients as $recipient) { // here you declare variables accesable in view file $dataToPassToEmailView = []; // **key** of this table is variable **name in view** $dataToPassToEmailView['no_inventaris'] = $get_no_inven; Mail::send('mailkedua', $dataToPassToEmailView, function($message) use ($subject, $recipient, $meta) { $message->to($recipient, 'Deputi Manager')->subject($subject); $message->from('app.staging@nutrifood.co.id','Kalibrasi Online'); }); }
and here is my mail view:
<p>Dear Deputi Manager,</p> <p>Berikut kami informasikan terdapat hasil kalibrasi terbaru alat dengan nomor inventaris {{$no_inventaris}} Mohon bantuannya untuk melakukan approval, silahkan akses "Link CALON" <a href="http://baf-staging-x2:3030/lihat_permohonan_deputi/">http://baf-staging-x2:3030/lihat_permohonan_deputi/</a></p> <p>Terima kasih,</p> <p>CALON</p>
i don’t understand where i’m doing wrong, thankyou!
Advertisement
Answer
You don’t need to wrap the result of your query in an array. Also if you only want the email
field from these records you could use pluck
to get a list of them:
$recipients = DB::table('users')->where('hak_akses','=','deputi')->pluck('email'); foreach ($recipients as $recipient) { ... }
This would make $recipient
a string for the email address.