Laravel 5.1 中的 Sendmail 主题
Sendmail Subject in 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.com', 'Avil');
$msg->to('mygmail@gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
我想要的主题不是 "Welcome to 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');
}
当我运行显示错误:
Undefined variable: data
请帮助我。非常感谢
您必须将 $data 传递给发送方法中的回调。请参考使用 Mail façade 的行。
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' , function($msg) use($data){
$msg->from('mygmail@gmail.com', 'Hung Nguyen');
$msg->to('mygmail@gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
我想使用变量发送带有主题的电子邮件,这是代码
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');
}
我想要的主题不是 "Welcome to 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');
}
当我运行显示错误:
Undefined variable: data
请帮助我。非常感谢
您必须将 $data 传递给发送方法中的回调。请参考使用 Mail façade 的行。
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' , function($msg) use($data){
$msg->from('mygmail@gmail.com', 'Hung Nguyen');
$msg->to('mygmail@gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}