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 :
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 ?
Which PHP function we are using
Why i am not getting emails when i submit the form
- 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.
Share with your friends:
Drag and Drop with Swapy and PHP
Hello , You might had issues with drag and drop options in your dashboard. here i found a new javascript […]
September 17, 2024
How To Generate A PDF from HTML in Laravel 11
Hello , I was trying to generate a PDF payment receipt for my SAAS application and when i search for […]
June 22, 2024
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
Digital Marketing Toolkit
Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits
Get Free Access Now