我正在使用laravel 5.6,并尝试将电子邮件发送到多个电子邮件地址。在这里,我的代码仅适用于一封电子邮件。如何使用多封电子邮件? 我正在使用可邮寄
这是我的控制人
public function sendEmail(Request $request)
{
Mail::send(new sendMail());
Session::flash('conf_email', 'ok');
return redirect('/send-email');
}
class SendMail extends Mailable
{
public function build(Request $request)
{
return $this->view('mail', ['msg' => $request->message])->to($request->to);
}
}
答案 0 :(得分:0)
to()函数接受多个用户(电子邮件(字符串)或对象的数组) 请参阅以下链接以获取更多信息 https://laravel.com/api/5.5/Illuminate/Contracts/Mail/Mailer.html#method_to
所以你可以做这样的事情
class SendMail extends Mailable
{
public function build(Request $request)
{
$users=User::all();
return $this->view('mail', ['msg' => $request->message])->to($users);
//or
return $this->view('mail', ['msg' => $request->message])->to(['test@test.com','test1@test.com']);
}
}
答案 1 :(得分:0)
You just need to change sendEmail function to:
public function sendEmail(Request $request)
{
Mail::to(['test@test.com','test1@test.com'])->send(new sendMail());
Session::flash('conf_email', 'ok');
return redirect('/send-email');
}