1
votes

I'm testing a contact from with the submission on the local server. dev.localhost

The error I'm getting is

The requested URL /volunteer-success.php was not found on this server.

I'm new to PHP. I'm trying to submit a form, email the message+name, and then redirect the user to a thankyou screen.

My HTML is as follows...

<form action="volunteer-submit.php" method="post" name="contact_form" data-parsley-validate>
    <textarea name="message" id="message" placeholder="Message" required></textarea> 
    <input type="text" placeholder="Your Name" id="name" name="name" required>
    <input type="email" placeholder="Your Email Address" id="email" name="email" required>
    <input type="submit" class="submit" value="Submit">
</form>

The PHP for sending the email is as follows

$to      = "[email protected]";
$subject = 'Email';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: '.$_POST["email"]. "\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n".
'X-Mailer: PHP/' . phpversion();

 $message = '<html><head><title></title></head><body>';
 $message .= '<p>Hi Ben, </p>';
 $message .= '<p>'.$_POST['message'].' </p>';
 $message .= '<p>'.$_POST['email'];
 $message .= '</body></html>';



mail($to, $subject, $message, $headers);

//Redirect

header("Location:volunteer-success.php"); /* Redirect browser */

?>

Would love to know why it's not redirecting. I've saved the php files alongside the index.html file onto the dev.localhost.

*example emails used

3
"The requested URL /volunteer-success.php was not found on this server." says file isn't available on the apt location. Try doing absolute address to that file eg. header("Location:yourdomain.com/volunteer-success.php"); - Abhinav Gauniyal
try to: header("Location: /volunteer-success.php"); or: header("Location: ./volunteer-success.php"); - Magicianred
Is the code you've shown above in the actual volunteer-submit.php file or is it included from another file? - Tieson T.
@Magicianred thanks! "Location: ./volunteer-success.php"); worked - user3785994
btw, there needs to be a space after Location:, which you don't have in your example code, maybe that's the error. - nonchip

3 Answers

2
votes

Try this -

Use exit(); after header()

because after redirecting page to another the code below the header shouldn't be execute.

header("Location: ./volunteer-success.php"); /* Redirect browser */
exit();

and one more thing. check for the space in your file after and before

 // Before shouldn't be any space
 <?php 


  ?>
// After shouldn't be any space as well
0
votes
header("Location: ./volunteer-success.php");

Enjoy your code! :)

-6
votes

I guess you should use javascript redirection

<script>window.location.href="volunteer-success.php";</script>

coz, most of the time php Header() won't work