A Step-by-Step Guide to Creating a PHP Form and Sending Data to an Email Address


In the world of web development, forms are essential tools for collecting user data and interacting with website visitors. In this tutorial, we’ll walk you through the process of creating a PHP form and configuring it to send data to an email address. By the end of this guide, you’ll have a functional form that allows users to submit information and have it delivered directly to your designated email inbox.


  • Basic understanding of HTML and PHP
  • A web hosting environment that supports PHP (e.g., Apache, PHP-enabled server)
  • Access to a text editor (e.g., Notepad++, Visual Studio Code)

Step 1: Set Up Your HTML Form Create an HTML file (e.g., contact.html) and add the following code to set up your form:

<!DOCTYPE html>
    <title>Contact Form</title>
    <h2>Contact Us</h2>
    <form action="process.php" method="post">
        <label for="name">Name:</label>
        <input type="text" name="name" required><br>
        <label for="email">Email:</label>
        <input type="email" name="email" required><br>
        <label for="message">Message:</label><br>
        <textarea name="message" rows="4" cols="50" required></textarea><br>
        <input type="submit" value="Submit">

Step 2: Create the PHP Processing Script Create a new file named process.php. This file will handle the form submission and send the data to the specified email address.

    $name = $_POST["name"];
    $email = $_POST["email"];
    $message = $_POST["message"];

    $to = "your@email.com"; // Replace with your email address
    $subject = "New Form Submission";
    $headers = "From: $email";

    if (mail($to, $subject, $message, $headers)) {
        echo "Thank you for your submission!";
    } else {
        echo "Oops! Something went wrong.";

Step 3: Upload Your Files Upload both the contact.html and process.php files to your web server. Make sure they are in the same directory.

Step 4: Test Your Form Open a web browser and navigate to your contact.html page. Fill out the form fields and click the “Submit” button. If everything is set up correctly, you should see a success message after submitting the form. Additionally, you should receive an email at the specified email address with the form data.

Conclusion: Congratulations! You’ve successfully created a PHP form that sends user-submitted data to an email address. This simple guide provides the foundation for building more advanced forms and enhancing your website’s interactivity. Feel free to customize the form’s appearance and add more fields as needed to suit your specific requirements.

Share post:




More like this

OnePlus 12: Display Delights and Charging Champions OxygenOS 13 – A Breath of Fresh Air

OnePlus 12: Redefining the "Flagship Killer" in 2024? The OnePlus...

Paytm: To Buy, or Not to Buy? A Deep Dive for Share Market Investors

Navigating the Paytm Rollercoaster: A Share Market Investor's Guide One97...

[WhatsApp Launched] Use Two Accounts on the Same Phone – Conversations Made Easy

Calling all multitaskers, rejoice! WhatsApp finally heard our pleas...

Sudhir Chaudhary: A prominent figure in Indian journalism

Sudhir Chaudhary: The face of Aaj Tak Sudhir Chaudhary is...