I am trying to create a PHP contact form. But the mail is going to spam. Can anyone please help me to fix this problem
pasting my code here
<?php
$error = "";
$successMsg = "";
if($_POST){
if(!$_POST['email']){
$error .= "An emailaddress is required<br>";
}
if(!$_POST['subject']){
$error .= "The subject is required<br>";
}
if(!$_POST['content']){
$error .= "The content field is required<br>";
}
if ($_POST['email'] && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) == false) {
$error .= "Not a valid email address";
}
if($error != ""){
$error = '<div class="alert alert-danger" role="alert"><p><strong>There were error(s)in your form:</strong></p>' . $error .'</div>';
}
else{
$emailTo = "asfdc@gmail.com" ;
$subject = $_POST['subject'];
$content = $_POST['content'];
$headers = "From: ".$_POST['email'] ;
if(mail($emailTo,$subject,$content,$headers)){
$successMsg = '<div class="alert alert-success" role="alert"><p><strong>Your msg was sent we\'ll get back to you ASAP!</strong></p></div>';
}else{
$error = '<div class="alert alert-danger" role="alert"><p><strong>your msg couldn\'t be sent-please try again later </strong></p></div>';
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<div class="container">
<h1>Get in touch!</h1>
<div id="error">
<? echo $error.$successMsg; ?>
</div>
<form method="post">
<fieldset class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email"
placeholder="Email address">
</fieldset>
<fieldset class="form-group">
<label for="subject">Subject</label>
<input type="text" class="form-control" id="subject" name="subject">
</fieldset>
<fieldset class="form-group">
<label for="content">What would you like to ask us?</label>
<textarea class="form-control" id="content" rows="3" name="content"></textarea>
</fieldset>
<button type="submit" id="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<script type="text/javascript">
$("form").submit(function (e) {
var error="";
if($("#email").val() == ""){
error += "The email field is required<br>";
}
if($("#subject").val() == ""){
error += "The subject field is required<br>";
}
if($("#content").val() == ""){
error += "<p>The content field is required.<br>";
}
if(error != ""){
$("#error").html('<div class="alert alert-danger" role="alert"><p><strong>There were error(s)in your form:</strong></p>' + error +'</div>');
}
return false;
else{
return true;
}
});
</script>
</body>
</html>