简体   繁体   中英

Contact form won't submit on button press

Struggling to get my contact form to send. I've pasted the code below

When i fill in the form and push send, nothing happens. I've tried using a button as opposed to an input submit but that still does nothing. I've had forms like this before work fine but now I just can't get this to send. Any clues?

<form id="contact-form" method="post" action="process.php">
  <div class="row">
    <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
      <div class="form-group" id="name-field">
        <div class="form-input">
          <input type="text" class="form-control" id="form-name" name="form-name" placeholder="Full Name">
        </div>
      </div>
    </div>
    <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
      <div class="form-group" id="email-field">
        <div class="form-input">
          <input type="email" class="form-control" id="form-email" name="form-email" placeholder="Email address">
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
      <div class="form-group" id="name-field">
        <div class="form-input">
          <input type="text" class="form-control" id="form-address" name="form-address" placeholder="Address of the works">
        </div>
      </div>
    </div>
    <div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">
      <div class="form-group" id="email-field">
        <div class="form-input">
          <input type="text" class="form-control" id="form-phone" name="form-phone" placeholder="Phone number">
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
      <div class="form-group" id="phone-field">
        <div class="form-input">
          <input type="text" class="form-control" id="form-subject" name="form-subject" placeholder="Description of the works required">
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
      <div class="form-group" id="message-field">
        <div class="form-input">
          <textarea class="form-control" rows="6" id="form-message" name="form-message" placeholder="Further Information"></textarea>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
      <div class="form-group">
        <input type="submit" value="SEND FORM" />
      </div>
    </div>
  </div>
</form>
<?php
           {
          $to = "info@blank.co.uk";
          $subject = "Contact Page from ";
          $headers  = "From: A T L <noreply@blank.co.uk>\r\n";
         $headers .= "Reply-To: noreply@blank.co.uk\r\n";
    $headers .= "Return-Path: noreply@blank.co.uk\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset: utf8\r\n";
      $name = filter_input(INPUT_POST, 'form-name');
     $email = filter_input(INPUT_POST, 'form-email');   
       $address = filter_input(INPUT_POST, 'form-address');
       $telephone = filter_input(INPUT_POST, 'form-phone');
      $theirSub = filter_input(INPUT_POST, 'form-subject');
      $message = filter_input(INPUT_POST, 'form-message');

     $message = 
     "<span style='font-weight: bold;'>Name: </span>"."<br />".$name."<br />"."<br />".
     "<span style='font-weight: bold;'>Email: </span>"."<br />".$email."<br />"."<br />".
     "<span style='font-weight: bold;'>Address: </span>"."<br />".$address."<br />"."<br />".
     "<span style='font-weight: bold;'>Telephone: </span>"."<br />".$telephone."<br />"."<br />".
     "<span style='font-weight: bold;'>Email: </span>"."<br />".$email."<br />"."<br />".
     "<span style='font-weight: bold;'>Subject: </span>"."<br />".$theirSub."<br />"."<br />".
     "<span style='font-weight: bold;'>Message: </span>"."<br />".$message."<br />"."<br />";

     mail($to, $subject,"We have received a message via the online form at www.blank.co.uk<br /><br />" . 
     $message, $headers);
     echo "Your message was successfully sent. Please <a href='contact.php'>click here</a> to return to the site.";
      ?>
       <?php  }
       ?>

The $message variable is used twice... once to receive data from the form, and then you overwrite it? You may want to use a different variable for that. I changed to $msg.

Also, you have a lot of needless php tags. Maybe try something a little cleaner like this to start:

<?php
$to = "info@blank.co.uk";
$subject = "Contact Page from ";
$headers  = "From: A T L <noreply@blank.co.uk>\r\n";
$headers .= "Reply-To: noreply@blank.co.uk\r\n";
$headers .= "Return-Path: noreply@blank.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$name = filter_input(INPUT_POST, 'form-name');
$email = filter_input(INPUT_POST, 'form-email');   
$address = filter_input(INPUT_POST, 'form-address');
$telephone = filter_input(INPUT_POST, 'form-phone');
$theirSub = filter_input(INPUT_POST, 'form-subject');
$msg = filter_input(INPUT_POST, 'form-message');

$message = 
"<span style='font-weight: bold;'>Name: </span>"."<br />".$name."<br />"."<br />".
"<span style='font-weight: bold;'>Email: </span>"."<br />".$email."<br />"."<br />".
"<span style='font-weight: bold;'>Address: </span>"."<br />".$address."<br />"."<br />".
"<span style='font-weight: bold;'>Telephone: </span>"."<br />".$telephone."<br />"."<br />".
"<span style='font-weight: bold;'>Email: </span>"."<br />".$email."<br />"."<br />".
"<span style='font-weight: bold;'>Subject: </span>"."<br />".$theirSub."<br />"."<br />".
"<span style='font-weight: bold;'>Message: </span>"."<br />".$msg."<br />"."<br />";

mail($to, $subject,"We have received a message via the online form at www.blank.co.uk<br /><br />" . $message, $headers);
echo "Your message was successfully sent. Please <a href='contact.php'>click here</a> to return to the site.";
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM