联系表单将不会在按下按钮时提交

问题描述 投票:0回答:1

[努力获取我的联系表。我粘贴了下面的代码

当我填写表格并推送发送时,没有任何反应。我尝试使用按钮而不是输入提交,但是仍然没有任何作用。在正常工作之前,我已经收到过这样的表格,但是现在我无法发送此表格。有任何线索吗?

<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 = "[email protected]";
          $subject = "Contact Page from ";
          $headers  = "From: A T L <[email protected]>\r\n";
         $headers .= "Reply-To: [email protected]\r\n";
    $headers .= "Return-Path: [email protected]\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  }
       ?>
php html contact-form
1个回答
0
投票

$ message变量被使用两次...一次从表单接收数据,然后覆盖它?您可能要为此使用其他变量。我更改为$ msg。

而且,您有很多不必要的php标签。也许尝试像这样的清洁器开始:

<?php
$to = "[email protected]";
$subject = "Contact Page from ";
$headers  = "From: A T L <[email protected]>\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Return-Path: [email protected]\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.";
?>
© www.soinside.com 2019 - 2024. All rights reserved.