简体   繁体   中英

php header redirect doesn't work

I've created a mail form. A PHP page reads the input, sends it out to a mail and then it should redirect to a certain page. Pretty straight forward, done it before. The mail gets send, but you don't get redirected.

HTML form:

<form action="mailversturen.php" method="post">
<input type="text" name="naam" placeholder="Naam" class="inputtype" /><br />
<input type="text" name="email" placeholder="Email" class="inputtype" /><br />
<textarea name="bericht" placeholder="Bericht"></textarea>
<input type="reset" value="Reset" class="buttontype" />
<input type="submit" value="Verstuur" class="buttontype" />
</form>

PHP code:

<?php
$name = $_POST['naam'];
$email = $_POST['email'];
$message = $_POST['bericht'];

$to = "name@domain.com";
$subject = "Bericht van $name";
$headers = "From: $email \r\n";

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

header('Location: http://www.newlocation.nl/');
?>

What am I doing wrong?

Try adding @ob_start(); after your opening <?php tag.

This turns on output buffering. I use it in combination with all header(...) redirects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM