tags:

views:

99

answers:

6

well am trying to use the header to send information, but my html is already outputting information, I tried to fix the problem by using the ob_start() function to no avail

    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();
A: 

Here you're trying to redirect to a different page and show a message. It can't happpen.

Instead, try using a link, or echo-ing:

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

in your <HEAD>.

In your case, you want this to be instant, so:

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

The better alternative, is simply to not require the page until after the if.

Lucas Jones
+5  A: 

You need to call ob_start before any output has happened. So, for example, as the first statement in your main PHP script file (make sure that there is nothing before your <?php like some whitespace of a BOM).

Gumbo
A: 

If i remember correctly the header(); is executed at the end of the execution of the php script , so try moving it in the beginning of the if

Cheers

Aviatrix
A: 

You have to buffer the html output, not the php logic. E.g:

ob_start();
<html>...
/* PHP */
...
ob_end_flush();
erenon
+6  A: 

Check if any scripts included before the ob_start() function are outputting HTML. Sometimes an included file can contain a space after the PHP closing tag. That space will be outputed as is. To fix this, leave the PHP closing tag from your file.

E.g.

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

Can give you some good headaches. This is fine and fixes the above problem:

<?php
 class someClass {
  ...
 }
TheGrandWazoo
A: 
header('Location: http://www.foo.com/emailNotification.html');

1 space after Location:

and

full url

With Your Dynamic HTTP_HOST

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

Chris.

chris