<?php
error_reporting(E_ALL ^ E_NOTICE);

// Start a session to hold the first variable pages
session_start();

// The email address this form will be sent to
$sendEmails = Array("support@cervion.com", "hunterballen@gmail.com");
//$sendEmails = Array("chris@cervion.com");
$emailTemplate = <<<EOF
<html>
<head><title>Portal: Support Request Submission</title></head>
<body>
<h2>Support Request Form Submission</h2>
<div style="margin-top:30px;font-size:12pt;">
<b>Customer Name:</b> %name% <br />
<b>Customer Company:</b> %company% <br />
<b>Request Date:</b> %date% <br /><br />
<b>Customer Phone:</b> %phone% <br />
<b>Customer IP:</b> %ip% <br /><br />
</div>
<div style="margin-top:20px;">
<b style="font-size:12pt;">Support Issue:</b><br /> <div style="font-size:11pt;">%issue%</div>
</div>
</body>
</html>
EOF;


/*
 * Function to send the email to the owner
 */
function sendMail() {
	global $emailTemplate, $sendEmails;
	$name = $_SESSION['form_data']['name'];	// Form submitters name
	$company = $_SESSION['form_data']['company'];	// Form submitters company
	$issue = $_POST['issue'];	// Form issue
	$phone = $_POST['phone']; 	// Form phone
	
	setcookie("company",$company,time()+(60*60*24*30));	// Set a cookie to remember the clients company name
	
	$date = date("m/d/Y g:i A", time());	// Date of contact
	
	$ip = $_SERVER['REMOTE_ADDR'];	// Get the users IP address

	// Replace the template values with the form values
	$emailTemplate = str_replace(array('%name%','%company%','%phone%','%ip%','%date%','%issue%'), array($name,$company,$phone,$ip,$date,nl2br($issue)), $emailTemplate);
	
	// Implode the email address with a comma
	if(count($sendEmails) > 1) {
		$to = implode(",",$sendEmails);
	}
	else {
		$to = $sendEmails[0];
	}
	
	$subject = 'Portal: Support Request Submission';
	
	$headers = "From: support@cervion.com\r\n";
	$headers .= "Reply-To: support@cervion.com\r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
	
	mail($to,$subject,$emailTemplate,$headers);
}
?>