2014-10-09 70 views
0
另一页

我有一个表格我的HTML文档中,当按下提交按钮,窗体调用文件form.php的。现在在form.php中,我想将它重定向回我的主页并重置以前填充的表单。我已经尝试了下面的代码,但我得到了一个空白页。 Google网址只是默认设置。PHP上提交重定向到

<?php 
 
if ($_POST['submit']) { 
 
    if (mail ($to, $subject, $body, $from)) { 
 
\t \t // To redirect to home page 
 
\t \t header("Location:http://www.google.com"); 
 
    } else { 
 
     echo '<p>Oops! An error occurred. Try sending your message again.</p>'; 
 
    } 
 
} 
 
?>

感谢您的帮助球员。

+0

请检查服务器日志,如果可能的话 – Vickrant 2014-10-09 06:31:26

+3

提示张贴在这里:写'退出()''后header' – diEcho 2014-10-09 06:32:24

+0

如何获得呢?我使用Filezilla作为ftp客户端 – ggguu 2014-10-09 06:42:10

回答

1

您可以尝试的JavaScript重定向方式页面:

例子:

$url='http://www.google.com'; 

    echo '<script>window.location = "'.$url.'";</script>'; 
    die; 

它可以帮助... !!

+0

这很好。谢了哥们。我认为这个话题解决了。非常感谢大家,你们真棒。 – ggguu 2014-10-09 07:00:30

+0

谢谢,很高兴帮助,堆栈溢出Rockzz ... !! @@ !! – 2014-10-09 07:02:31

1

也许你这个头(......),然后写了一些回声或打印。尝试ob_start();

欲了解更多信息请按照this

0

我没有看到你的HTML,但你有你的命名与属性name="submit"提交按钮?

其他情况下$_POST['submit']将是空的,你的剧本什么也不做。

0

您好我曾经使用过你的代码。我可以重定向到google.Please检查下面的代码..在我看来,我认为这个问题可能是邮件function.check,如果邮件来了或不..如果邮件来了,它会定义重定向到谷歌页面..

<?php 
if ($_POST['submit']) 
{ 
    $to="[email protected]"; 
    $subject="googletest"; 
    $body="test"; 
    if (mail ($to, $subject, $body)) 
    { 
     // To redirect to home page 
     header("Location:http://www.google.com"); 
    } else { 
     echo '<p>An error occurred. Try sending your message again.</p>'; 
    } 
} 
?> 
<form name="form" id="form" action="form.php" method="post"> 
<input type="submit" value="submit" name="submit"> 
</form> 
+0

这也是我的html。提交时我收到了电子邮件。它只是不会重定向。但我用echo'';而不是标题,现在很好。顺便说一句,你知道如何解决这个问题? – ggguu 2014-10-09 07:06:23

0

试试这个:

<?php 
if ($_POST['submit']) { 
    $to="[email protected]"; 
    $subject="Mail"; 
    $body="redirect"; 
    $from="[email protected]"; 
    if (mail($to, $subject, $body, $from)) { 
     // To redirect to home page 
     header("Location:http://www.google.com"); 
     exit(); 
    } else { 
     echo '<p>Oops! An error occurred. Try sending your message again.</p>'; 
    } 
} 
?> 

它我的本地服务器上的工作。

+0

我不知道什么是错的。我已经使用JavaScript而不是Sharaz Nabi所建议的,它工作。 – ggguu 2014-10-09 07:05:02