简体   繁体   English

php标头重定向不起作用

[英]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. PHP页面读取输入,将其发送到邮件,然后应重定向到特定页面。 Pretty straight forward, done it before. 非常简单,以前做过。 The mail gets send, but you don't get redirected. 邮件被发送,但是您没有被重定向。

HTML form: HTML形式:

<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代码:

<?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(); 尝试添加@ob_start(); after your opening <?php tag. 打开<?php标记后。

This turns on output buffering. 这将打开输出缓冲。 I use it in combination with all header(...) redirects. 我将其与所有header(...)重定向结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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