PHP Contact form send email – Website integration ✔️

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 

How to collect emails from website contact form ?

We are creating a PHP script to capture the contact from data and sending you to via email

Which PHP function we are using

We are using the mail() function in PHP

Why i am not getting emails when i submit the form

These are the main reasons you are not getting emails
  • You may using your localhost to test : (you need a server to test the emails)
  • You are using a free hosting . (Free hosting like 000webhost doesnt allow you to send emails from the server)
  • From email address not valid. (create a from email address in ur mailbox)

Is this email is free for lifetime.

Yes, you can use this email until your hosting provider block you from using it. Normally all hosting providers will give you unlimited email sending access.

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 integrate Paypal API in Laravel

Are you looking to integrate Paypal API in your Laravel project for seamless payment processing? Look no further! In this […]

April 3, 2024

How to integrate Razorpay API in Laravel

Integrating payment gateways into web applications has become an essential part of e-commerce websites. In this tutorial, we will discuss […]

April 3, 2024

Laravel 11 Ajax CRUD Operation Tutorial Example

**Mastering CRUD Operations with Laravel 11 Ajax: A Comprehensive Tutorial** In the world of web development, interaction between the front-end […]

April 3, 2024

Login as Client in Laravel – Login with user id

**Unlock the Power of Laravel with Login as Client – Login with User ID** Laravel, the popular PHP framework, offers […]

April 3, 2024

Digital Marketing Toolkit

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

Get Free Access Now