无法 POST /contact.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26056150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:07:25  来源:igfitidea点击:

Cannot POST /contact.php

phphtmlforms

提问by azhpo

I have a contact form on my website and I get the "Cannot POST /contact.php" error.

我的网站上有一个联系表格,但出现“无法 POST /contact.php”错误。

This is my form at html page:

这是我在 html 页面上的表单:

<form role="form" action="contact.php" method="post">
<div class="form-group">
    <label for="InputName">Nom</label>
    <div class="input-group">
        <input type="text" class="form-control" name="name" id="InputName" placeholder="Nom" required>
        <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
    </div>
</div>
<div class="form-group">
    <label for="InputEmail">Email</label>
    <div class="input-group">
        <input type="email" class="form-control" id="InputEmail" name="email" placeholder="Email" required>
        <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
    </div>
</div>
<div class="form-group">
    <label for="InputEmail">Sujet</label>
    <div class="input-group">
        <input type="text" class="form-control" id="InputEmail" name="subject" placeholder="Sujet" required>
        <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
    </div>
</div>
<div class="form-group">
    <label for="InputMessage">Message</label>
    <div class="input-group">
        <textarea name="message" id="InputMessage" class="form-control" rows="5" required></textarea>
        <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
    </div>

</div>

<div class="form-group">
    <label for="InputReal">5 + 10? (Spam Checker)</label>
    <div class="input-group">
        <input type="text" name="human" class="form-control" name="InputReal" id="InputReal" required>
        <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
    </div>
</div>

    <input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-left">
</form>

And then I tried my PHP code (contact.php). I don't know if there is something wrong as I am very bad at PHP:

然后我尝试了我的 PHP 代码 (contact.php)。我不知道是否有什么问题,因为我在 PHP 方面非常糟糕:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '[email protected]';
$subject = $_POST['subject'];
$human = $_POST['human'];

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

if ($_POST['submit'] && $human == '15') {
    if (mail($to, $subject, $body)) {
        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 != '15') {
    echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

If anyone who understands PHP could help, that would be amazing.

如果任何了解 PHP 的人都可以提供帮助,那就太棒了。

Thanks in advance.

提前致谢。

采纳答案by Bhupender Keswani

As said by Sakthi Karthik, you need to check the directory/path of contact.php.

正如Sakthi Karthik所说,您需要检查contact.php.

Also in the condition you should check:

同样在您应该检查的情况下:

if(isset($_POST['submit'] && $human == '15')

Likewise:

同样地:

else if(isset($_POST['submit'] && $human != '15')

回答by Sakthi Karthik

make sure you have contact.phpfile in same folder or not. you have missing tag </form>

确保您contact.php在同一文件夹中是否有文件。你缺少标签</form>