html – PHP form gets submitted but the data is blank-ThrowExceptions

Exception or error:

My html code looks like this, also included is the php file. The form gets submitted and the data headings like “Name :”, “Email :”, etc. is there but required data is blank.

Please see the example below:

Name:
Phone:
E-Mail:
Message:

Can someone explain, what’s wrong with my code?

<form id="zpro-contact-form" action="mailer.php" method="POST">

  <div class="box_sec3">
    <div class="three_box2">
      <p class="text3">Name</p>
      <div class="form_box">
        <input class="input-field form" name="name" type="text" required="">
      </div>
    </div>
    <div class="three_box2">
      <div class="form_box">
        <p class="text3">Phone</p>
        <input class="tel-number-field long form" name="phone" type="text" required="">
      </div>
    </div>
    <div class="three_box2">
      <div class="form_box">
        <p class="text3">Email</p>
        <input class="input-field form" name="email" type="email" required="">
      </div>
    </div>

  </div>
  <div class="box_sec4">
    <p class="text3">Message</p>
    <textarea name="message" id="message" class="textarea-field form2" required=""></textarea>
  </div>
  <div class="wapper">
    <label>
      <span>&nbsp;</span><input type="submit" id="submit_btn" value="SUBMIT" class="send" /> 
    </label>
    <p class="zpro-send-message"></p>
</form>

Here is the mailer.php I have tried replacing variable “REQUEST” with “POST” but its still coming back blank.

   <?php
        //print_r($_FILES);
        //include("dbconnection.php");
        //include("header.php");
        //include('st.html');
        //include('contact.php');
        //print_r($_POST);
        //session_start();

    ?>
    <?php 
         $to = "....@......";
         $subject = "Inquiry from website" ;
         $email = $_REQUEST['email'] ; 

         $message .= " Name: ".$_REQUEST['name'] ; 
         $message .= "\n Phone: ".$_REQUEST['phone'] ; 
         $message .= "\n E-Mail: ".$_REQUEST['email'] ; 
         $message .= "\n Message: ".$_REQUEST['message'] ; 
         $headers = "From: $email";
         $headers = "MIME-Version: 1.0" . "\r\n";
         $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
         $sent = mail($to, $subject, $message, $headers) ; 

         if($sent) 
         {
             echo "<script>window.location='/thank_you.html'</script>";
         }
         else 
         {
             echo "<script>window.location='/thank_you.html'</script>";
         }
     ?> 
How to solve:

Leave a Reply

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