<?php
$fname = $_POST['name'];
$name = $fname;
if($_POST['lname']!=""){$name.=" ".$_POST['lname'];}
$email = $_POST['email'];
$phone = $_POST['phone'];
$comment = $_POST['message'];
$toEmail = "netizenstech@gmail.com";
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$showMessage = '';
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {    
    $subject = "Contact us email";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: '.$email."\r\n".
    'Reply-To: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();    
    $message = 'Hello,<br/>'
    . 'Name:' . $name . '<br/>' ;
    if($phone!=""){
    $message .= 'Phone:' . $phone . '<br/>' ;
    }
    $message .='E-mail:' . $email . '<br/>' 
    . 'Message:' . $comment . '<br/><br/>';     
    mail($toEmail, $subject, $message, $headers);
    $showMessage = "Your Query has been received, We will contact you soon.";   
} else {
    $showMessage =  "Invalid email";
}
$jsonData = array(
    "message"   => $showMessage
);
echo json_encode($jsonData); 
?>