<?php
//If the form is submitted
if(isset($_POST['name'])) {

	//Check to make sure that the name field is not empty
	if(trim($_POST['name']) == '') {
		$hasError = true;
	} else {
		$name = trim($_POST['name']);
	}

	//Check to make sure that the phone field is not empty
	if(trim($_POST['company']) == '') {
		// $hasError = true;
	} else {
		$company = trim($_POST['company']);
	}

	//Check to make sure that the name field is not empty
	if(trim($_POST['url']) == '') {
//		$hasError = false;
	} else {
		$weburl = trim($_POST['url']);
	}

	//Check to make sure that the subject field is not empty
if (isset($_POST['subject'])) {
	if(trim($_POST['subject']) == '') {
		//$hasError = true;
		$subject='Website Contact';
	} else {
		$subject = trim($_POST['subject']);
	}
} else {
		$subject='Website Contact';
}

	//Check to make sure sure that a valid email address is submitted
	if(trim($_POST['email']) == '')  {
		$hasError = true;
	} else if (!filter_var( trim($_POST['email'], FILTER_VALIDATE_EMAIL ))) {
		$hasError = true;
	} else {
		$email = trim($_POST['email']);
	}

	//Check to make sure comments were entered
	if(trim($_POST['comment']) == '') {
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$comments = stripslashes(trim($_POST['comment']));
		} else {
			$comments = trim($_POST['comment']);
		}
	}

	//If there is no error, send the email
	if(!isset($hasError)) {
		$emailTo = 'info@stessa-it-solutions.com'; // Put your own email address here
		//$emailTo = 'root@localhost'; // Put your own email address here
		$body = "Name: $name \n\nEmail: $email \n\nCompany: $company \n\nSubject: $subject \n\nComments:\n $comments";
		$headers = 'From: STESSA Contact Form <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

		$res=mail($emailTo, $subject, $body, $headers);
                //$res="$emailTo $subject $body $headers";
		$emailSent = true;
$error = error_get_last();
		//var_dump($error);
echo "Message delivered.";
	} else {
            echo ".";
        } 
} else {
  echo "..";
}
?>
