Creating Contact Form in PHP and HTML

Published May 25, 2017

A contact form on your site allows visitors to communicate with the site owner. By using this form, you can keep your email address relatively safe from unwanted emails. Plus, you can easily connect it to your database and keep a record of users who are trying to contact you. After that, you can easily contact them via their email addresses.

For this tutorial, we will use the local machine. First, you have to install XAMPP or WAMPP to execute and test your code. Basic knowledge on HTML and PHP to understand the code is also required. I will be using HTML5 input type and input required attribute for form validation in order to check if all the fields are filled correctly. You will require an editor like Notepad++ to write your code. Following are the steps to create a PHP form and connect it to your MySQL database. I will be using XAMPP to execute my PHP code. You will also need PHPmyAdmin.

Getting Started
Locate the folder where you have installed your XAMPP and then open htdocs folder. Usually, it is saved in C:/xampp/htdocs. Now, create a new folder in your htdocs folder and name it ContactForm. Save all the files that we will create in this folder.

Step 1: Create a Contact Form
Create a contact form giving below with simple HTML5 validation and save it with .php extension. Value which will be written between the double quotes in attribute Name like name=”u_name” in input tags work as a variable name. These attributes will contain the data from the form that we will use to save in our database by retrieving these value in our thankyou.php page. There are two methods to send your form data to your PHP page: GET and POST. To learn the difference between them, click here. I will be using POST as it hides the user data and there is no limit to send data.

Read full article at Creating Contact Form in HTML and PHP.

Discover and read more posts from Muhammad Azaz Qadir
get started
Enjoy this post?

Leave a like and comment for Muhammad

1