1

Problem is when I submit this form it shows something went wrong. Could somebody check where I've made a mistake.

HTML code:

  <div class="main">
   <div class="info">Give your feedback</div>
     <form action="mail.php" method="post" name="form" class="form-box">
     <label for="name">Name</label><br>
     <input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
     <label for="email">Email</label><br>
     <input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
     <label for="phone">Phone</label><br>
    <input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
     <input type="submit" name="submit" value="Send" class="sub-btn">
   </form>
 </div>

PHP code

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

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

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

1 Answers1

0

You have no $headers variable declared when you call the mail function.

ecomnet
  • 36
  • 2
  • I removed this variable.But stiil problem – Jasur Kurbanov Sep 02 '17 at 10:57
  • I tested your code and it works (there is a missing braket at the end for the "if" in mail.php, besides that it works). The problem must be from the server you are sending, gmail requires SPF and DKIM to properly deliver you email. – ecomnet Sep 02 '17 at 12:41