<?php

class HomeController extends BaseController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/

	public function showWelcome()
	{
		return View::make('hello');
	}

	public function enviar()
	{
		$inputs   = Input::all();
		$rules = array(
				'name'=>'required',
				'email'=>'required|email',
				'message'=>'required',
				'g-recaptcha-response' => 'required|captcha',
		);
	
		$validator = Validator::make($inputs,$rules);
		if($validator->passes())
		{
			Mail::send('emails.mail', array('mensaje'=>nl2br(Input::get('message')),'name'=>Input::get('name'),'email'=>Input::get('email'),'phone'=>Input::get('phone'),'empresa'=>Input::get('empresa')), function($message) {
				$message->to('info@ssbc.mx',Input::get('name'))->subject('Mensaje de la forma de contacto');
				$message->replyTo((Input::get('email')));
			});
			return Redirect::to("enviado");
		}
		else
		{
			$errors= $validator->errors();
			return Redirect::to("/")->with('errors',$errors);
		}
	}
	
	public function enviado()
	{
		return View::make('emails.enviado');
	}
}
