Support the ongoing development of →
Requests Forms Mail
Last updated 1 year ago.
public function authorize()
	return false;

You are returning false, which forbids access to everybody. You should change that to return true; to allow everybody to submit a form.


Of course. I forgot this. Thank you very much. I also forgot to add use Redirect; to PageController.

But now I have error

InvalidArgumentException in UrlGenerator.php line 278:
Route [contacts] not defined.

Np. :)

The new issue is because the route() method is for named routes. The to() method is for a specific URI. In your routes file, you defined the contacts URI, but you didn't give it a "name". You only specified the uri and action.

			// uri		// controller action
Route::get('contacts', 'PageController@contacts');

Changing it like this assigned a "name" to your route.

			// uri		// route name		// controller action
Route::get('contacts', ['as' => 'contacts', 'uses' => PageController@contacts']);

You can read more about that in the docs:

Another option you can do is change the route() method to the to() method.

return Redirect::to('contacts')->withCategory($category)
                                          ->with('message', 'Thanks for contacting us!');
Last updated 8 years ago.

I want to use input information in $message variable like this

$message->from($request->input('email'), $request->input('name') );
$message->from($request->get('email'), $request->get('name') );

but have

ErrorException in PageController.php line 46:
Undefined variable: request

for me it is not obvious why inside one function $request->get('name') works in Array and then doesn't work in $message

	public function sendmail(ContactFormRequest $request)
		$category = Category::where('sef', '=', 'contacts')->first();
            	'name' => $request->get('name'),
            	'email' => $request->get('email'),
            	'user_message' => $request->get('message')
        			$message->from('[email protected]', $request->get('name') );
        			$message->to('[email protected]', 'Admin');
        			$message->subject('Письмо с сайта - страница контактов.');

    	return Redirect::route('contacts')->withCategory($category)
    									  ->with('message', 'Thanks for contacting us!');
Last updated 8 years ago.

From the PHP site themselves (

Closures may also inherit variables from the parent scope. Any such variables must be passed to the use language construct.

So, try changing



function($message) use ($request)
Last updated 8 years ago.

thanks a lot. this solved the issue


Sign in to participate in this thread!


Your banner here too?

schel4ok schel4ok Joined 15 Feb 2015


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.