I mates,I have this code in my Controller:
$name = Input::get('fname')." " .Input::get('lname');
$message = Input::get('message');
$email = Input::get('email');
$subject = Input::get('subject');
$phone = Input::get('phone');
$area = \App\Area::find(1)->name;
$ticket = \App\Area::find(1)->ticket_sent;
Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message)
{
$message->from('[email protected]', 'Name');
$message->to('[email protected]');
$message->subject('Support');
});
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');
It works so good, but I'm trying to change two rows in:
$message->from($email, $name);
$message->subject($subject);
But it doesn't work. What am I doing wrong? I don't understand.
please check the code, need to add use after "function ($message)"
$name = Input::get('fname')." " .Input::get('lname');
$message = Input::get('message');
$email = Input::get('email');
$subject = Input::get('subject');
$phone = Input::get('phone');
$area = \App\Area::find(1)->name;
$ticket = \App\Area::find(1)->ticket_sent;
Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message) use ($email, $name,$subject)
{
$message->from($email, $name);
$message->to('[email protected]');
$message->subject($subject);
});
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');
You need to use use()
with anonymous functions to pass variables:
.... function ($message) use ($email, $name) { ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With