Support the ongoing development of Laravel.io →
Requests Forms Mail
Last updated 2 years ago.
0
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.

0

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.
0

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: http://laravel.com/docs/master/routing

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 9 years ago.
0

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

$message->from($request->input('email'), $request->input('name') );
or
$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();
		Mail::send('emails.contacts',
        	array(
            	'name' => $request->get('name'),
            	'email' => $request->get('email'),
            	'user_message' => $request->get('message')
        		), 
        	function($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 9 years ago.
0

From the PHP site themselves (http://php.net/manual/en/functions.anonymous.php):

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)

to

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

thanks a lot. this solved the issue

0

Sign in to participate in this thread!

Eventy

Your banner here too?

schel4ok schel4ok Joined 15 Feb 2015

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.