I suspect this is because when using a closure (anonymous function) in PHP, if not explicitly passing the variables through - you need to use the "use" keyword so that they're available for use...
$subj = $_POST['subject'];
Mail::send('emails.contactmessage', array('from' => $sendername, 'email' => $email, 'msg' => $msg), function($message) use ($subj) {
$message->to('[email protected]', 'Joe User')->subject($subj);
});
Also, when dealing with querystring (get) or form post data, you should use Laravel's helpers - e.g. Input::get('subject')
Nice.
And it works!
And I suppose I can populate other fields in anonymous functions with this 'trick'.
Thanks,
Bill
Hi AndrewBNZ,
Very nice, Thank you.
Regards, Sambhav
AndrewBNZ said:
I suspect this is because when using a closure (anonymous function) in PHP, if not explicitly passing the variables through - you need to use the "use" keyword so that they're available for use...
$subj = $_POST['subject']; Mail::send('emails.contactmessage', array('from' => $sendername, 'email' => $email, 'msg' => $msg), function($message) use ($subj) { $message->to('[email protected]', 'Joe User')->subject($subj); });
Also, when dealing with querystring (get) or form post data, you should use Laravel's helpers - e.g. Input::get('subject')
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community