我是laravel的新手。我需要发送电子邮件到表中的所有记录,使用where条件(where exam_id = 1)。每条记录都会得到电子邮件消息是它自己的名称和电子邮件。已存储在表中。可以自己为此提出任何建议吗?发送电子邮件至表中所有条件使用laravel的条件
先感谢
public function sendmail(Request $request) {
$email = DB::table('student')->select('email','exam_id')->where('exam_id','=','1')->get();
$email= mysql_query("SELECT email FROM student WHERE exam_id='1' ;");
$title = $request->input('title');
$content = $request->input('content');
if(mysql_num_rows($email))
{
while($elist_result = mysql_fetch_array($email))
{
Mail::send('email', ['title' => $title, 'content' => $content],function ($message)
{
$message->from('[email protected]', 'dhivya');
$message->to('[email protected]');
$message->cc($elist_result);
$message->subject("Hello");
} );
}
}
return response()->json(['message' => 'message send successfully']);
}
分享您在代码的努力。一种简单的方法是将查询结果存储在对象中并循环播放。 – Shubhamoy
我收到了我的代码Mr.Shubhamoy Chakrabarty.Thanks for your reply.Please为我建议 –
你遇到什么错误?看起来你的代码是正确的,只需稍作修改,比如使用PDO或mysqli_ *而不是mysql_ *(因为这已经在PHP7中被弃用了)。 – Ronald