Core PHP, How To, PHP Beginners

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...

Written by Bikash · 1 min read >

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 nicer to use Ajax with PHP.

Go below to Download Complete Source code File


Here are 3 major steps to create a jQuery contact Form that 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 will create a simple HTML form where we set the ID attribute which is used by the JavaScript file to take the data from the HTML form and send it to the PHP file.


Create a JS Ajax File

First I need to explain the complete code which is important to use on the complete Ajax file.

Input Code


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

Send Data on Form Submit


Here we will send the input data to the PHP file for sending the details by 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

In this file, we will take the data using the PHP POST method and send mail.

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

Here is the complete PHP code (mailer.php)

Download the Complete Source code of Send Email Using Ajax

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

Check more on the PHP mail function, here

Also Check:

Happy Coding..!

Was this article helpful?
Written by Bikash
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. Profile

3 Replies to “jQuery Contact Form Send Email Using Ajax”

Leave a Reply

Your email address will not be published. Required fields are marked *