<?php 

$your_email ='markkhanippbx@gmail.com';// <<=== update to your email address



session_start();

$errors = '';

$name = '';
$visitor_cn = '';
$visitor_phone = '';
$visitor_email = '';
$visitor_preee = '';

if(isset($_POST['submit']))

{

    

    $name = $_POST['name'];
    $visitor_cn = $_POST['contactname'];
    $visitor_phone = $_POST['phone'];
	$visitor_email = $_POST['email'];
    $visitor_preee = $_POST['preee'];
    ///------------Do Validations-------------

    if(empty($name)||empty($visitor_email))

    {

        $errors .= "\n Name and Email are required fields. ";   

    }

    if(IsInjected($visitor_email))

    {

        $errors .= "\n Bad email value!";

    }

    if(empty($_SESSION['6_letters_code'] ) ||

      strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)

    {

    //Note: the captcha code is compared case insensitively.

    //if you want case sensitive match, update the check above to

    // strcmp()

        $errors .= "\n The captcha code does not match!";

    }

    

    if(empty($errors))

    {

        //send the email

        $to = $your_email;

        $subject="Contact form TheBestService.";

        $from = $your_email;

        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

        

        $body = "A user  $name submitted the contact form on The Best Services website:\n".

        "Company Name: $name\n".

        "Contact Name: $visitor_cn \n".

        "Phone No: $visitor_phone \n". 

		"Email  : $visitor_email \n" .

		"Preffered Method  : $visitor_preee \n" .

        "IP: $ip\n";    

        

        $headers = "From: $from \r\n";

        $headers .= "Reply-To: $visitor_email \r\n";

        

        mail($to, $subject, $body,$headers);

        

        header('Location: thank-you.php');

    }

}



// Function to validate against any email injection attempts

function IsInjected($str)

{

  $injections = array('(\n+)',

              '(\r+)',

              '(\t+)',

              '(%0A+)',

              '(%0D+)',

              '(%08+)',

              '(%09+)'

              );

  $inject = join('|', $injections);

  $inject = "/$inject/i";

  if(preg_match($inject,$str))

    {

    return true;

  }

  else

    {

    return false;

  }

}

?>







<!DOCTYPE html>

<html lang="en">

<head>

	<title>Contact form</title>

	<meta charset="UTF-8">

	<meta name="viewport" content="width=device-width, initial-scale=1">

<!--===============================================================================================-->

	<link rel="icon" type="image/png" href="fav.png"/>

<!--===============================================================================================-->

	<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">

<!--===============================================================================================-->

	<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">

<!--===============================================================================================-->

	<!-- <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css"> -->

<!--===============================================================================================-->

	<!-- <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css"> -->

<!--===============================================================================================-->

	<!-- <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css"> -->

<!--===============================================================================================-->

	<!-- <link rel="stylesheet" type="text/css" href="css/util.css"> -->

	<link rel="stylesheet" type="text/css" href="css/main.css">

	<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> 

<!--===============================================================================================-->

</head>

<body>



	<div class="contact1">

		<div class="container-contact1">

			<div class="contact1-pic js-tilt" data-tilt style="margin-top:-200px;">

				<img src="Logos-17.png" alt="IMG">

			</div>





						<?php

						if(!empty($errors)){

						echo "<p class='err'>".nl2br($errors)."</p>";

						}

						?>

						<div id='contact_form_errorloc' class='err'></div>



			<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" class="ui-form wow bounceInUp contact1-form validate-form contact100-form validate-form " data-animation="bounceInUp" name="sentMessage animated">

				<span class="contact1-form-title">

					Get in touch

				</span>



				<div class="wrap-input1 validate-input" data-validate = "Name is required">

					<input class="input1" type="text" name="name" value='<?php echo htmlentities($name) ?>' placeholder="Company Name">

					<span class="shadow-input1"></span>

				</div>

				<div class="wrap-input1 validate-input" >

					<input class="input1" type="text" name="contactname" value='<?php echo htmlentities($visitor_cn) ?>' placeholder="Contact Name">

					<span class="shadow-input1"></span>

				</div>


				<div class="wrap-input1 validate-input" data-validate = "Number is required">

					<input class="input1" type="text" name="phone" value='<?php echo htmlentities($visitor_phone) ?>' placeholder="Phone Number">

					<span class="shadow-input1"></span>

				</div>

				
				<div class="wrap-input1 validate-input" data-validate = "Name is required">

					<input class="input1" type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>' placeholder="Email">

					<span class="shadow-input1"></span>

				</div>



				



				<div class="wrap-input1 validate-input" >

					
					
					<label class="input1" for="preee" name="preee" value='<?php echo htmlentities($visitor_preee) ?>' style="height: 50px;border-radius: 25px;padding: 13px 23px;color: #9999A3;">Preffered Method Of Contact:</label>

						<select id="preee" name="preee" style="position: absolute;margin-top: -47px; margin-left: 260px;background:#E6E6E6;color:black;">
						<option label="Call">Call</option>
						<option label="Text">Text</option>
						<option label="Email">Email</option>
						
						</select>
					<span class="shadow-input1"></span>

				</div>



				<p>

									<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' class="imgg" ><br><br>

									



									<input id="6_letters_code" name="6_letters_code" class="form-control input1" placeholder="Enter the code above here" type="text">

								<br>	<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>

									</p>

									<br>





				<div class="container-contact1-form-btn">

					<button  type="submit" value="Submit" name='submit' placeholder="Enter the code above here" id="submit" class="btn btn-light btn-radius btn-brd grd1 btn-block contact1-form-btn">

						<span>

							Send Email

							<i class="fa fa-long-arrow-right" aria-hidden="true"></i>

						</span>

					</button>

				</div>

			</form>

			<script language="JavaScript">



									var frmvalidator  = new Validator("contact_form");



									frmvalidator.EnableOnPageErrorDisplaySingleBox();

									frmvalidator.EnableMsgsTogether();



									frmvalidator.addValidation("name","req","Please provide your name"); 

									frmvalidator.addValidation("email","req","Please provide your email"); 

									frmvalidator.addValidation("email","email","Please enter a valid email address"); 

									frmvalidator.addValidation("phone","req","Please enter a valid phone number");

									frmvalidator.addValidation("6_letters_code","req","Please ender Captcha code");

									</script>

									<script language='JavaScript' type='text/javascript'>

									function refreshCaptcha()

									{

									    var img = document.images['captchaimg'];

									    img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;

									}

									</script>

		</div>

	</div>









<!--===============================================================================================-->

	<script src="vendor/jquery/jquery-3.2.1.min.js"></script>

<!--===============================================================================================-->

	<script src="vendor/bootstrap/js/popper.js"></script>

	<script src="vendor/bootstrap/js/bootstrap.min.js"></script>

<!--===============================================================================================-->











</body>

</html>

