PHP Contact form send email – Contact form with php mail for your website

Hello coders, today we are going to learn how to connect the Contact form with PHP mail to your website – php contact form send email

Lots of beginners who know to create a website using HTML and CSS sometimes struggles with config php contact form send email.

they know to create good looking contact forms but don’t know how to connect that with their email address.

Why do we use the PHP Contact form on our website?

We use the contact form for website visitors to communicate with website owners. That is a must thing building modern websites, because most people like to submit an email enquiry before they call the business. so you must design a contact form in every website.

most of the websites doesn’t have a backend to store the contact form submission data. so you have to build a mail function to send the email to the website owner email.

If you want to know how to create website backend for storing contact form submissions. please let me know. i will make a tutorial about that.

A few people ask me about this and I made this tutorial.

Step 1: Create a HTML contact form

<form action="mail.php" method="post">
    <label for="name">Your Name</label>
    <input type="text"  name="name" placeholder="Your name..">

    <label for="lname">Email</label>
    <input type="email"  name="email" placeholder="Your email..">
    <label for="message">Message</label>
    <textarea  name="message" placeholder="Write something.." style="height:200px"></textarea>

    <input type="submit" value="Submit">

Step 2 is to create the mail.php file when someone clicks the submit button it will go to the mail.php file which we defined in the form action


//get data from form  

$name = $_POST['name'];
$email= $_POST['email'];
$message= $_POST['message'];
$to = "[email protected]";
$subject = "Mail From website";
$txt ="Name = ". $name . "\r\n  Email = " . $email . "\r\n Message =" . $message;
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";

That’s all. I made an explainer video and I will link it here .. you can check that if you have any doubts .. also you can ask me via discord

Download Source Code : 

php contact form send email



If you want to know how to make attachment submission with phpemail You can checkout my another tutorial by clicking this link 

Sometimes your servers may not allow you to run phpmail function. that time you can use the SMTP method. You can see that by clicking this link 

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

How to Compress Image using PHP

In this tutorial we are going to talk about how to Compress Images using PHP, You can reduce the image […]

13 October, 2021

How to backup and download Database using PHP

Learn How to backup and download Database using PHP. Most of the time we develop some applications, the most important […]

8 October, 2021

How to make a Zip file using PHP

Hello Everyone In this tutorial, we are going to make a zip file using PHP. and we also unzip the […]

How to make pretty URL in PHP using .htaccess

Hello Everyone, Here in this tutorial, you will learn How to make a pretty URL in PHP using .htaccess. and […]

18 September, 2021

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now