Is anyone can suggest what is the best way or how can I send email to all the users that are located in my news_subscibers table with dynamic data from a form? I tried and was a able to send email to a hard coded email.
public function sendNewsEmail(Request $request)
{
$this->validate($request,[
'subject' => 'bail|string|required|string|max:100',
'bodymessage' => 'bail|string|required|string|min:10',
]);
$data = array(
'subject' => $request->subject,
'bodymessage' => $request->bodymessage
);
$subscriber_emails = NewsSubscriber::pluck('subs_email')->toArray();
foreach ($subscriber_emails as $mail)
{
Mail::send('email.news-email', $data, $mail, function($message) use ($data, $mail){
$message->from('[email protected]');
$message->to('[email protected]');
$message->cc($mail);
$message->subject($data['subject']);
});
Session::flash('success', 'Your message was sent!');
return redirect()->back();
};
}
I would like to send the email to all users in news_subscribers table.