Hello bretheren and programming Gurus? Am new and blank about php and just trying to experiment to get things as i want. Am using the code below but it does not validate data input and also does not redirect to the index page specified in it.I want if the fileds are empty on clicking submit, it must return an error and prompts to fill in all fields.i also want an option where a person can attach files to the form. Kindly correct errors for me in the code and give me a complete fully functional code. Thank you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
if(isset($_POST['submit']))
{
$from_add = "contactform@yourwebsite.com";
$to_add = "yourname@yourwebsite.com";
$subject = "Your Subject Name";
$message = "Name:$name \n Email: $email \n Phone: $phone \n
Message: $message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent";
}
}
print "<p>Thank you $name for your message,
we will be in contact shortly. <a href=\"index.php\">Click here</a>
to continue </p>" ;
?>