我可以正确发送消息,但是我对变量主题有问题,我怎样才能将变量$ subject发送到Mail方法。
->subject($subject)
我收到一个未定义的变量,这是我的代码。
public function enviarmensaje()
{
$email = Request::input('email');
$subject= Request::input('subject');
$name = Request::input('nombre');
$message = Request::input('message');
$data = array( 'name' => $name , 'correo' => $email , 'mensaje' => $message,'subject'=> $subject );
Mail::send('contact', $data , function ($message) {
$message->to('email@gmail.com','To anyone')->subject("Contact form");
});
}
答案 0 :(得分:2)
您必须use
$subject
变量:
Mail::send('contact', $data , function ($message) use ($subject) {
$message->to('email@gmail.com', 'To anyone')->subject($subject);
});
或者,您可以在闭包本身内调用Request::input('subject')
:
Mail::send('contact', $data , function ($message) {
$message->to('email@gmail.com', 'To anyone');
$message->subject(Request::input('subject'));
});