﻿<?php

$to = 'systems@deltaintel.com';

function url(){
  return sprintf(
    "%s://%s",
    isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
    $_SERVER['SERVER_NAME']
  );
}

    if($_POST) 
	{

		// access
		$secretKey = '6LeAG7IaAAAAANmC25zefnRg8WEnxoBvrCo-IkhK';
		$captcha = $_POST['g-recaptcha-response'];

		if(!$captcha){
			echo '<p class="alert alert-warning">Please check the the reCAPTCHA box.</p>';
			exit;
		}

		$name = trim(stripslashes($_POST['name']));
		$email = trim(stripslashes($_POST['email']));
  		$subject = "DeltaIntel.com Contact Form Submission";	
		$phone = trim(stripslashes($_POST['phone']));
		$contact_message = trim(stripslashes($_POST['message']));
		$message = " ";
		$ip = $_SERVER['REMOTE_ADDR'];
		$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
		$responseKeys = json_decode($response,true);

		if(intval($responseKeys["success"]) !== 1) {
			echo '<p class="alert alert-warning">Please check the the reCAPTCHA box.</p>';
		} else {

			// Set Message
			$message .= "Email from: " . $name . "<br />";
			if ($phone != '') { $message .= "Phone: " . $phone . "<br />"; } else { $message .= "Phone: N/A <br />"; }

			$message .= "Email address: " . $email . "<br />";
			$message .= "Message: <br />";
			$message .= nl2br($contact_message);
			$message .= "<br /> ----- <br /> This email was sent from your site " . url() . " contact form. <br />";

			// Set From: header
			$from =  " <" . $to . ">";

			// Email Headers
			$headers = "From: " . $from . "\r\n";
			$headers .= "Reply-To: ". $from . "\r\n";
			$headers .= "MIME-Version: 1.0\r\n";
			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

			ini_set("sendmail_from", $to); // for windows server
			$mail = mail($to, $subject, $message, $headers);

			if ($mail) { echo "OK"; }
		}
	} else { echo "Something went wrong. Please try again."; }

?>