使用 php 脚本允许人们将他们的电子邮件添加到邮件列表中。当它成功地将电子邮件写入 .txt 文档时,它会在白页上显示一条成功消息。我希望它重定向到我设计的页面,使其看起来像网站的其他部分。我在其他地方读到我需要使用 header 函数,但我不知道将其放在哪里,因为我的代码的前面部分包含输出。
我认为这是相关代码:
// Write to file if email doesn't already exist
if ($emailexists != "yes") {
// Write to the list and give success message
fwrite($fh, "$_POST[email]\n");
$msg = "Your e-mail address $EmailFix was successfully added to the list!";
}
// Close the list
fclose($fh);
}
然后这个:
// Show success message if there was one and end script, and no errors were encountered
} elseif (isset($msg)) {
echo "<b>" . $msg . "</b>\n";
echo "</body>\n";
echo "</html>\n";
exit;
}
最佳答案
尝试使用
header("Location: http://...");
或
header("Location: filename.php");
在调用 header 函数之前确保没有 HTML 输出!
关于表单成功后php重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6232240/