<?php
$message = ""; 
if(isset($_POST['submit'])){
	$to = "support@piperfx.com"; // Your email address
	$name = $_POST['name'];
	$from = $_POST['email'];
    $subject = $_POST['subject'];
	$phone = $_POST['phone'];
	$message = "<!DOCTYPE html>
	<html>
	<head>
	</head>
	<body>
	<table rules='all' border='1' style='border-color: #666;' cellpadding='10'>
    <tr style='background: #eee;'><td colspan='2'><strong>Enquiry Details</strong> </td></tr>
    <tr>
        <td><strong>Name:</strong></td>
        <td>".$_POST['name']."</td>
    </tr>
    <tr>
        <td><strong>Mobile:</strong></td>
        <td>".$_POST['phone']."</td>
    </tr>
    <tr>
        <td><strong>Email:</strong></td>
        <td>".$_POST['email']."</td>
    </tr>
    <tr>
        <td><strong>Subject:</strong></td>
        <td>".$_POST['subject']."</td>
    </tr>
    <tr>
        <td><strong>Message:</strong></td>
        <td>".$_POST['message']."</td>
    </tr>
	</table>
	</body>
	</html>";
	
	$subject = $_POST['subject'];
	
	// Set content-type header for sending HTML email 
	$headers = "MIME-Version: 1.0" . "\r\n"; 
	$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
	
	$headers .= "From:" . $from . "\r\n";
	
	$result = mail($to,$subject,$message,$headers);
	if ($result) {
		// $message = "Your Message was sent Successfully!";
		echo '<script type="text/javascript">alert("Your Message was sent Successfully!");</script>';
// 		echo '<script type="text/javascript">window.location.href = window.location.href;</script>';
		echo '<script type="text/javascript">location.assign("index.php");</script>';
		

	}else{
		// $message = "Sorry! Message was not sent, Try again Later.";
		echo '<script type="text/javascript">alert("Sorry! Message was not sent, Try again Later.");</script>';
	   // echo '<script type="text/javascript">window.location.href = window.location.href;</script>';
		echo '<script type="text/javascript">location.assign("index.php");</script>';
	}
	// header('Location: contact.php');
}
?>