How to Send Contact Form Data on Email Using PHP Code -

How to Send Contact Form Data on Email Using PHP Code

Sometimes, you may need to send data from the HTML form to your email address through a PHP script. That is why you are here, read the blog to find out how to do it.
You can find plenty of resources online that will tell you how to load the sent data into the database. But if you are a beginner, not everything is explained in depth. This article should be a simple place to start.

Step 1: Copy this HTML Code And Paste It In Your HTML File

            <div class="row contact-wrap"> 
                <div class="status alert alert-success" style="display: none"></div>
                <form  class="contact-form" name="contact-form" method="post" action="sendemail.php">
                    <div class="col-sm-5 col-sm-offset-1">
                        <div class="form-group">
                            <label>Name *</label>
                            <input type="text" name="name" class="form-control" required="required">
                        <div class="form-group">
                            <label>Email *</label>
                            <input type="email" name="email" class="form-control" required="required">
                        <div class="form-group">
                            <label>Phone No.</label>
                            <input type="number" name="phone" class="form-control">
                        <div class="form-group">
                            <label>Business Name</label>
                            <input type="text" name="buname"  class="form-control" placeholder="Eg.For School,  for Any other Business">
                    <div class="col-sm-5">

                        <div class="form-group">
                            <label>Message *</label>
                            <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                        <div class="form-group">
                            <button type="submit" name="submit" class="btn btn-primary btn-lg">Submit Message</button>


Step 2: Copy this PHP Code And Paste It In Your PHP File And Name Is As sendemail.php

Step 3: Run The Code

    if (isset($_POST['submit'])){
    $name = $_POST['name']; 
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $buname = $_POST['buname'];
    $message = $_POST['message']; 

    $email_from = $email;
    $email_to = '[email protected]';  //replace with your email

    $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Mobile No.: ' . $phone . "\n\n" . 'Business Name: ' . $buname . "\n\n" . 'Message: ' . $message;

    $success = @mail($email_to, 'Website Enquery', $body, 'From: <'.$email_from.'>');
   header('location: thank-you.html');
    }  else {
    header('location: enqury.html');

Leave a Reply

Your email address will not be published. Required fields are marked *