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">
  </form>

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

 



<?php
//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]";
if($email!=NULL){
    mail($to,$subject,$txt,$headers);
}
//redirect
header("Location:thankyou.html");
?>

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 get the next value of an array and loop it in the array in PHP

Do you know How to get the next value of an array and loop it in the array in PHP […]

July 28, 2023

New Open Source CRM for project Management and Invoicing

I’m excited to announce the launch of my new open source project: Gmax CRM. an invoicing and project management tool […]

December 31, 2022

Post View Counts WordPress plugin (Documentation)

The Post View Counts plugin is a simple tool for tracking and displaying the number of views for each post […]

December 30, 2022

How to create Laravel Flash Messages

Laravel flash messages are a convenient way to display one-time notifications to the user after a form submission or other […]

December 22, 2022

Digital Marketing Toolkit

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

Get Free Access Now