4

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.

1
  • Or consider using Laravel 5.3, the mail sending has been rewritten and is much easier now: laravel.com/docs/5.3/mail Commented Aug 31, 2016 at 11:03

2 Answers 2

4

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');
Sign up to request clarification or add additional context in comments.

1 Comment

if it helps you then please accept my answer @therock24
4

You need to use use() with anonymous functions to pass variables:

.... function ($message) use ($email, $name) { ....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.