我在提交此表单时发送了一封php邮件。我希望页面在提交后重定向。我遇到的问题是表单提交,旧页面重新加载,然后重定向开始。有关如何跳过重新加载并进行重定向的任何想法?代码如下:
<?php
if(isset($_POST['button_pressed']))
{
$to ='email@email.com';
$subject = 'New Sign Up!';
$message = $_POST['MERGE1'] . ' ' . $_POST['MERGE2'] . ' with the email address ' . $_POST['MERGE0'] . ' has just registered using the Sign Up Now Popup Form';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$url = 'http://www.example.com/?sub=true';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
?>
答案 0 :(得分:0)
更改以下行:
$url = 'http://www.example.com/?sub=true';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
为:
$url = 'http://www.example.com/?sub=true';
header("Location:" . $url)
答案 1 :(得分:0)
header()函数将原始HTTP标头发送到客户端。
header('Location: http://www.example.com/?sub=true');