<?php

include dirname(dirname(__FILE__)).'/config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;
if ($post) {
	if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
		$secret = '6Le6qRIsAAAAAMgNM7La7EtxRu9idlCkB2qkLpTo';
		$verify = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
		$response = json_decode($verify);
		if($response->success) {
			include 'functions.php';
			date_default_timezone_set("Europe/London");
			$date = date('F j, Y, g:i a');
			$name = stripslashes($_POST['name']);
			$companyname = stripslashes($_POST['companyname']);
			$email = trim($_POST['email']);
			$phone = stripslashes($_POST['phone']);
			$fromemail = trim($_POST['email']);
			$contacttype = ($_POST['contacttype']);
			//$noemp = stripslashes($_POST['noemp']);
			//$userid = stripslashes($_POST['userid']);
			$postcode = ($_POST['postcode']);
			$bc="madhosh@efileready.com";
			$subject = "Request Info : ableoffice.co.uk CONTACT US - ".$date."";
			$details = stripslashes($_POST['message']);
			$message = "This person has reqested info on ableoffice.co.uk Application. \n\n";
			$message.="Name : ".$name."\n\n";
			$message.="Company Name : ".$companyname."\n\n";
			$message.="Mail ID : ".$fromemail."\n\n";
			$message.="Phone : ".$phone."\n\n";
			$message.="Contacting for : ".$contacttype."\n\n";
			//$message.="User ID : ".$userid."\n\n";
			$message.="Post Code : ".$postcode."\n\n";
			//$message.="No of Employees : ".$noemp."\n\n";
			$message.="Query : ".$details."\n\n";
			$message.="***** END OF MESSAGE *****";
			$error = '';
			if(!$name) {
				$error .= 'Please enter your name.<br />';
			}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

			if(!$details || strlen($details) < 15) {
				$error .= "Please enter your  message or enquiry. It should have at least 15 characters.<br />";
			}
			if(!$error) {
				$mail = mail(WEBMASTER_EMAIL, $subject, $message,
				"From: ".$name."\r\n"
				."Reply-To:".$email."\r\n"
				."Bcc:".$bc."\r\n"
				."X-Mailer: PHP/" . phpversion());
				if($mail) {
					echo 'OK';
				}
			} else {
				echo '<div class="alert alert-danger">'.$error.'</div>';
			}
		} 
		else {
			echo '<div class="alert alert-danger">reCAPTCHA verification failed. Please reload page &amp; try again</div>';
			exit();
		}
	} else {
		echo '<div class="alert alert-danger">Please check recaptcha box</div>';
		exit();
	}
}
?>