联系表单重定向到index.php页面显示页面中的代码

时间:2014-07-05 22:02:23

标签: php html

我找到了这个代码,用于通过index.php页面重定向我的联系表单,但它显示了重定向页面上的部分代码。代码对我来说没问题,我不知道我错过了什么。这是:

<html>
<head>



<style type= "text/css">
   body {
    background-color: #C2C2FF;
  } 

#holla {
width: 500px;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
 }
</style>


</head>
<body>

    <div id= "holla">
       <img src="smiley.png">
    <?php
      $name = $_POST['name'];
      $email = $_POST['email'];
      $message = $_POST['message'];
      $from = 'From: webpage'; 
      $to = 'emailaddressblocked'; 
      $subject = 'Hello';
      $human = $_POST['human'];

      $body = "From: $name\n E-Mail: $email\n Message:\n $message";

      if ($_POST['submit'] && $human == '4') {                 
      if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>';
      } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
      } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
      }
      }
     ?>
    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

您应该更改此部分代码:

if ($_POST['submit'] && $human == '4') {
    if (mail ($to, $subject, $body, $from)) {
        echo '<p>Your message has been sent!</p>';
    } else {
        echo '<p>Something went wrong, go back and try again!</p>';
    } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
    }
}

成:

if ($_POST['submit']) {
    if ($human == '4') {
        if (mail($to, $subject, $body, $from)) {
            echo '<p>Your message has been sent!</p>';
        } else {
            echo '<p>Something went wrong, go back and try again!</p>';
        }
    } else {
        echo '<p>You answered the anti-spam question incorrectly!</p>';
    }
}

在你的代码的早期,你有其他的,如果在一起,你在if语句中重复相同的条件,并且肯定不是你想要做的。