<?php
if(!isset($_POST['submit']))
{
	//This page should not be accessed directly. Need to submit the form.
	echo "error; you need to submit the form!";
}
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$street = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$inforSrc = $_POST['infoSrc'];
$industry = $_POST['industry'];
$arena = $_POST['arena'];
$decMaker = $_POST['decMaker'];
$worked = $_POST['worked'];
$advisor = $_POST['advisor'];
$comments = $_POST['comments'];
$emailList = $_POST['emailList'];

//Validate first
if(empty($fName, $lName)||empty($email)) 
{
    echo "Name and email are mandatory!";
    exit;
}

if(IsInjected($email))
{
    echo "Bad email value!";
    exit;
}

$email_from = 'chriswalters444@gmail.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $fName $lName.\n".
    "Here is the message:\n $street $city $state $zip $phone $email $infoSrc $industry $arena $decMaker $worked $advisor $comments $emailList".
    
$to = "chriswalters444@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done.



// 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;
  }
}
   
?> 