Codeconia -Learn Programming

Contact form with phpmail for your website

Hello coders, today we are going to learn how to connect the Contact form with PHP mail to your website

Lots of beginners who know to create a website using HTML and CSS sometimes struggles with the contact form. they know to create good looking contact form but don’t know how to connect that with their email address.

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

 

Ajith Jojo

2 comments

  • Hi

    Meet your best Buds – True Wireless Earbuds with amazing sound, convenience, portability, & affordability!

    Order yours now at 50% OFF with FREE Shipping: musicontrol.online

    Kind Regards,

    Minerva
    Contact form with phpmail for your website –

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular