Your code is not good. Seems like you are a beginner. I have drafted a better code for you. Try this!
$contactName = (!empty($_POST['contactname']))?$_POST['contactname']:null;
$companyName = (!empty($_POST['companyname']))?$_POST['companyname']:null;
$phone = (!empty($_POST['phone']))?$_POST['phone']:null;
$email = (!empty($_POST['email']))?$_POST['email']:null;
$subject = (!empty($_POST['subject']))?$_POST['subject']:null;
$message = (!empty($_POST['message']))?$_POST['message']:null;
$postMaster ="[email protected]";
$to = "[email protected]";
if($_POST){
$body = "Hello! You have received a new mail from ".$companyName."<br><br><b>Phone:</b> ".$phone.".<br><br><b>Message:</b> ".$message;
$headers = "From: $postmaster
";
$headers .= "Reply-To: $email
";
$headers .= "Content-Type: text/html; charset=iso-8859-1
";
if(mail($to,$subject,$body,$headers)){
header('Location: success.html');
exit();
}else{
header('Location: failed.html');
exit();
}
}
You must learn to write cleaner, shorter and well formatted codes. Also, I did not understand what your injection function does. Hence, I left that out. To me it seemed unnecessary. However, if you anyhow feel it was necessary for you, please feel free to include it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…