我想使用变量发送带有主题的电子邮件,这是代码
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail.com', 'Avil');
$msg->to('mygmail@gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
我想主题不是“欢迎使用 Laravel 5.1”,主题是
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail@gmail.com', 'Hung Nguyen');
$msg->to('mygmail@gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
当我运行显示错误时:
未定义变量:数据
请帮我。太感谢了