2009-11-21 84 views
2

也想使用头发送的信息,但我的HTML已经输出的信息,我试图通过使用ob_start()函数无济于事头PHP工作不

ob_start(); 
    require('RegisterPage.php'); 
    if(isset($_POST['register'])) 
    { 
     if(register($errormsg,$regnumber)) 
     { 
     $to = $_POST['email']; 
     $subject = "Registration"; 
     $txt = "You need to return to the Classic Records homepage and enter the number given in order to finish your registration ".$regnumber.""; 
     $headers = "From: [email protected]"; 
     mail($to,$subject,$txt,$headers); 
     header('Location:emailNotification.html'); 
     } 
     else $error=$errormsg; 
    } 
    ob_end_flush(); 

回答

6

检查ob_start()函数之前包含的任何脚本是否正在输出HTML。有时候,一个包含的文件可以在PHP结束标签之后包含一个空格。这个空间将会像现在这样输出。要解决这个问题,请保留文件中的PHP结束标记。

E.g.

<?php 
class someClass { 
    ... 
} 
?><whitespace> 

可以给你一些好头痛。这是罚款和解决上述问题:位置后

<?php 
class someClass { 
    ... 
} 
0

这里来解决这个问题您正试图重定向到不同的页面显示一条消息。它不能发生。

相反,尝试使用链接,或回声荷兰国际集团:

<meta http-equiv="Refresh" content="(delay in seconds);URL=(destination)"> 

<HEAD>

在你的情况,你想这是瞬间,所以:

<meta http-equiv="Refresh" content="0;URL=emailNotification.html"> 

更好的选择,简直是不需要的页面,直到if后。

5

您需要在任何输出发生之前致电ob_start。因此,例如,作为主PHP脚本文件中的第一条语句(确保<?php之前没有任何内容,如BOM的某些空格)。

0

如果我没记错的话header();在PHP脚本的执行结束时执行,所以尽量在如果

干杯

0

你必须缓冲HTML输出,而不是PHP逻辑的开始移动它。例如:

ob_start(); 
<html>... 
/* PHP */ 
... 
ob_end_flush(); 
0
header('Location: http://www.foo.com/emailNotification.html'); 

1空间:



完整的URL

与动态HTTP_HOST

header('Location: http://'.$_SERVER["HTTP_HOST"].'/emailNotification.html'); 

Chris。