1

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

This is my form at html page:

<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

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'myemail@email.com';
$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.

Thanks in advance.

Mauker
  • 11,237
  • 7
  • 58
  • 76
azhpo
  • 125
  • 1
  • 3
  • 11

3 Answers3

1

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

Also in the condition you should check:

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

Likewise:

else if(isset($_POST['submit'] && $human != '15')
Community
  • 1
  • 1
Bhupender Keswani
  • 1,218
  • 1
  • 9
  • 16
0

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

Sakthi Karthik
  • 3,105
  • 4
  • 25
  • 29
0

Make sure that you are running your web page in XAMP/htdocs/"your project folder"/contact.php

PHP is a server side language, and it needs to be run on server.

Start your XAMPP and make sure that Apache and MySQL are starded and running.