
Now we are going to design a HTML contact form use PHP and iQuery. PHP with jQuery AJAX delivers you high end user friendly method to send HTML contact form. In this process we are going to use two files,
- contactForm.html
- formProcess.php
1) contactForm.html
This file contains the form to be processed and the jQuery AJAX function call to execute the PHP file. Thus follows the example code for contactForm.html
Once the submit button in the form is clicked, it call jQuery AJAX function and start to execute formProcess.php
2) formProcess.php
This PHP file is used to get the form fields and send mail using PHP mail function.
";
// Your email address (to which the mail to be sent)
$to ='test@example.com';
// Checking for Mandatory Fields(checking whether required fields are empty)
if (filter_var($_POST["email"], FILTER_VALIDATE_EMAIL) && ($_POST["contactName"]!="") && ($_POST["message"]!="") && ($subject!="")&&($_POST['contactNumber']!=''))
{
// PHP Mail Send Function
mail($to,$subject,$message,$header);
// Success Message After sending Mail
echo "We've received your contact information, Will get back to you soon";
}
// Error Message if Required Fields are Empty
else {
echo "Fill out Required Fileds.
Try again\n";
}
?>
When formProcess.php file is called, it stars to execute php script in the server but it's hidden from user. The result is displayed in the given HTML area, here it's
By this way you can develop user friendly HTML contact form.
No comments:
Post a Comment