-1

Here is my html and PHP code, when I submit the form data, it targets me to the blank window where no errors are been reported neither the data is been sent to the mail, to be further noted my PHP display error and display startup errors are on.

HTML

 <!-- form start  -->
        <form action="mail_handler.php" method="post" name="form" class="form-box">


         <div class="col-sm-6">
          <div class="form-group">

           <input type="text" name="name" class="form-control" placeholder="Your Name">
         </div>
       </div>

       <div class="col-sm-6">
         <div class="form-group">
           <input type="email" name="email" class="form-control" placeholder="Your Email">
         </div>
       </div>

       <div class="col-sm-6">
        <div class="form-group">
          <input type="tel" name="phone" class="form-control" placeholder="Your Phone Number">
        </div>

        <div class="col-sm-12">
         <div class="textarea-message form-group">
           <textarea name="msg" class="textarea-message form-control" placeholder="Your Message" rows="5">

           </textarea>
         </div>
       </div>


       <div class="text-center">      
        <button type="submit" class="load-more-button">submit
        </button>
      </div>

    </form>

PHP

    <?php
            if(isset($_POST['submit']))
            {
            $name=$_POST['name'];
            $email=$_POST['email'];
            $phone=$_POST['phone'];
            $msg=$_POST['msg'];

            $to='xyz@gmail.com'; 
            $subject='Form Submission';
            $message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
            $headers="From: ".$email;

            if(mail($to, $subject, $message, $headers))
            {
            echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1>";
            }
            else
            {
            echo "Something went wrong!";
            }
            }
            ?>
Yash Shah
  • 125
  • 13

2 Answers2

0

add name="submit" in button input

JochenJung
  • 7,183
  • 12
  • 64
  • 113
Joseph
  • 11
  • 8
0

Instead of

<button type="submit" class="load-more-button">submit
</button>

Use

<button type="submit" name="submit" class="load-more-button">submit
</button>

Note the added name="submit"

Qirel
  • 25,449
  • 7
  • 45
  • 62
Croos Praveen
  • 86
  • 2
  • 8