PHP Contact Form: How to Create Contact Form Using HTML & PHP

Hi friends Hello today I am going to tell you how to create PHP Contact Form, and I will also tell about its backend php code that the backend of php works with our html bootstrap.
So friends, we start with this, first of all we have to create a normal html form which we will connect with our php backend, whatever data will be put inside the form, that data on our gmail or any other mail you data Can get Let’s start.

Contact Form HTML and CSS Tutorial

What you will learn:

  • The basics of CSS3 styling
  • How to create an HTML5 contact form
  • How to create an elegant CSS3 contact form

Action and Method of new.php

The last thing we will need to understand before starting our form is the use of INPUT – which will tell browsers to allow an input of text type, to complete a field. Using this along with textarea will allow us to create our form and create a space for users to input information that we will later use PHP to send via email.

Each one of these areas we create on our form will be given a NAME that we will also be using on our PHP document to mark the information being sent.

Taking a Look at Contact Form

Now let’s begin our example. We will create a very simple starting point that I will show you how to modify for your own needs. Understanding the code and how it works will help you use it better and help ensure you have less problems when placing this on a live website.

I will start with a very basic contact form to get us started. Here is the basic HTML that we will use to create our contact form.

HTML Form Code

Step 1



Friends, you saw that our html form is ready and we have validated it, so we will not use id here in our php backend, we will use name like name = “email”, and name = “subject” We are going to use etc here, let’s start php backend coding.

Contact Form PHP: How To Actually Create It?

Now, to make our form work, we will need to use a little PHP. This part is actually easier than most people think. We will be using the PHP $_POST function, and creating labels for each name that we have created in our form. This will allow us to further customize the form later on as well.

Step 2

Now we will create our new.php file – This is what will generate the email from the form and actually mail it:


Here you are all seeing how we have kept php backend code but you can also keep it in the same way, friends, if you have any kind of problem then you can ask us by making comments.

Share on:

Hello, I am Dharmendra Yadav and I am a Python Developer with experience in web development using Django, Flask, REST API, SQL, MySQL, HTML, CSS, JavaScript, WordPress, Oracle Cloud, AWS and Git. I also write technical articles where I explain web development and Software Engineering. Facebook , Linkedin

Leave a Comment