I have a php contact form, which is sending data via email, and would like to sanitise it. I understand the php method for this is done with the htmlspecialchars(
) function.
I'm new to php and can't seem to work out how to apply this to my contact from data? Do I put my mail()
function inside it?
Any assistance would be awesome.
PHP
if($_POST['submit']) {
if(!$_POST['name']) {
$error="<br>- Please enter your name";
}
if(!$_POST['email']) {
$error.="<br>- Please enter your email";
}
if(!$_POST['telephone']) {
$error.="<br>- Please enter your telephone number";
}
if(!$_POST['message']) {
$error.="<br>- Please enter your message";
}
if(!$_POST['radio']) {
$error.="<br>- Please confirm you agree to the Privacy Policy";
}
if ($error) {
$result='<div class="alert error">Whoops, there is an error. Please correct the following: '.$error.'</div>';
} else {
mail("example@example.com", "Contact Message", "Name: ".$_POST['name']."
Email: ".$_POST['email']."
Telephone: ".$_POST['telephone']."
Company: ".$_POST['company']."
Budget: ".$_POST['budget']."
Message: ".$_POST['message']);
{
$_POST= array();
$result='<div class="alert thankyou" role="alert">THANK YOU! WE\'LL BE IN TOUCH SHORTLY...</div>';
}
}
}