0
votes

I keep getting this error:

"Type error: Too few arguments to function App\Http\Controllers\PageController::App\Http\Controllers\{closure}(), 1 passed and exactly 2 expected"

For this little snippet of code:

public function contact(Request $request)  {
    Mail::raw($request->message, function($message, $request)
     {
         $message->from($request->email, $request->name);

         $message->to('info@test.com');
     });
      return view('quotation.index');  
}

When changing the $request->email to a email string the function does work. But the email needs to come from the email entered in the laravel form. Could someone help me fix this issue?

1
You are getting error on this line $message->from($request->email, $request->name); ? - Romantic Dev

1 Answers

4
votes

You are getting this error because you are passing variables to closure but in a wrong way.

You have to use use ($request) in closure if you want to pass a variable.

public function contact(Request $request)  {
    Mail::raw($request->message, function($message) use ($request)
     {
         $message->from($request->email, $request->name);

         $message->to('info@test.com');
     });
      return view('quotation.index');  
}

Hope this helps.