jQuery Contact Form Send Email Using Ajax

jQuery Contact Form Send Email Using Ajax, is a common feature of various websites. If you want to send the contact form details using Email then it can be do nicer using AJax with PHP.

Go below to Download Complete Source code File


Here are 3 major steps to create jQuery contact Form which can send email using Ajax,

  • Create a simple HTML form.
  • Create a PHP file that takes user data.
  • Create the main JS file which can send user data and trigger mail.

Send Mail From Localhost in PHP Using XAMPP

Create a simple HTML form

Here we create a simple HTML form where we set the ID attribute which is used by JavaScript file to take the data from the HTML form and send it to PHP file.


Create a JS Ajax File

First I explain the complete code which are important to use on the compete Ajax file.

Input Code


Here we take input from the HTML form using ID attribute.

Send Data on Form Submit


Here we send the input data to the PHP file for sending the details on mail.

JS Validation

Here we validate fields using var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

Complete JS File (main.js)

Create PHP File for Sending Form Data to Mail

On this file we take the data using PHP POST method and send mail.

If you want to use test on local machine, the mail function generally not working with localhost but you can do the same. Here is the some article to how we can do it,

Here is complete PHP code (mailer.php)

Download Complete Source code of jQuery Contact Form Send Email Using Ajax

Complete Source code of jQuery Contact Form Send Email Using Ajax

Here are complete details about how to create a Ajax based Contact form using PHP.

Also Check:

Happy Coding..!

Was this article helpful?
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
Posts created 188

3 thoughts on “jQuery Contact Form Send Email Using Ajax

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top