Skip to content
Advertisement

PHP script not working. Receiving error 404. Web server DOES support PHP

I have the following form and php script:

<form method="post" action="index.php">
    <h1>Contact</h1> 

    <label>Name</label>
    <input name="name" placeholder="Type Here">

    <label>Email</label>
    <input name="email" type="email" placeholder="Type Here">

    <label>Message</label>
    <textarea name="message" placeholder="Type Here"></textarea>

    <input id="submit" class="button" name="submit" type="submit" value="Submit">
</form>

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'SJW&T Contact Form'; 
    $to = 'someone@example.com'; 
    $subject = 'Hello';
    $human = $_POST['human'];

    $body = "From: $namen E-Mail: $emailn Message:n $message";

    if ($_POST['submit']) {              
        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>';
        } 
    }
?>

But my web host seems to be returning an error 404. I tried the suggestion in this thread, which is a near duplicate, but it did not work. Anyone see any syntax errors? My web host is 000webhost.com. It doesn’t give me an actual 404 message, but the URL it takes me to is error404.000webhost.com.

Advertisement

Answer

That might happen, when you don’t have the action page:

<form method="post" action="index.php">

You set the action page to index.php, so if that file doesn’t exist or located somewhere else, you might get a 404 error or Object not found.

Make sure you have index.php AND it exists in the same directory with your other files.

If you want to take the action on the page itself, then do:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement