简体   繁体   English

按下按钮时不会提交联系表格

[英]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? $message 变量被使用了两次...一次是从表单接收数据,然后你覆盖它? You may want to use a different variable for that.您可能希望为此使用不同的变量。 I changed to $msg.我改为 $msg。

Also, you have a lot of needless php tags.此外,您有很多不必要的 php 标签。 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.";
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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