<?php
include('../include/connection.php');
$name=$_POST['txtname'];
$phone=$_POST['txtphone'];
$email=$_POST['txtemail'];
$mess=$_POST['txtmessage'];


if(!empty($name) and !empty($email)){
    $to = "hello@afsarebrahim.com";
$subject = "General Enquiry";

$message = "
<html>
<head>
<title>Enquiry Details</title>
</head>
<body>
<table class='table table-striped'  width='100%' border='1' cellspacing='5'  cellpadding='5'>
<tr>
<td width='25%'>Name:</td>
<td width='75%'>$name</td>
</tr>
<tr>
<td width='25%'>Email:</td>
<td width='75%'>$email</td>
</tr>
<tr>
<td width='25%'>Phone:</td>
<td width='75%'>$phone</td>
</tr>
<tr>
<td width='25%'>Message:</td>
<td width='75%'>$mess</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= "From: <$email>" . "\r\n";
$headers .= "Reply-To: <$email>" . "\r\n";
// $headers .= 'Cc: whyshydeveloper@gmail.com' . "\r\n";

$mail=mail($to,$subject,$message,$headers);
if($mail){
    //$sql="INSERT INTO `enquiry` (`name`, `email`, `phone`, `address`, `subject`, `enquiry_for`, `msg`) VALUES ('$name', '$email', '$phone', '', '$subject', '', '$mess')";
    //$query=mysqli_query($conn,$sql);
    $msg['status']="true";
    $msg['msg']="Thank you for considering us as your go to choice for your requirements. Someone from our team will get in touch with you shortly.";
    echo json_encode($msg);
	exit();
}
else{
    $msg['status']="false";
    $msg['msg']="error, please try again";
    echo json_encode($msg);
	exit();
}

}
else{
    $msg['status']="false";
    $msg['msg']="Name , Email  Fields are required";
    echo json_encode($msg);
	exit();
}