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 data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

Export html table to excel, pdf, csv format using Datatable

Do you know how to export html table to excel, pdf, CSV, or excel format using Datatable? If you don’t […]

August 4, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Instagram Hashtag API PHP and JavaScript Integration with RapidAPI

Do you know how to integrate Instagram Hashtag API with your website? In this tutorial, I will show you how […]

August 2, 2022

Digital Marketing Toolkit

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

Get Free Access Now