Forum Moderators: coopster

Message Too Old, No Replies

Help needed with header() function

header() function won't work...

         

sofia

1:34 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



Hello all,

I'm very new to PHP, and have been desperately trying to make the submit button on my form redirect to a confirmation page. But the header() function keeps giving this kind of error message:

----------------
Warning: Cannot add header information - headers already sent by (output started at /customers/mydomain/mydomain/httpd.www/mysubdomain/header.php:1) in /customers/mydomain/mydomain/httpd.www/mysubdomain/mail2.php on line 5
---------------

My code looks like this in the header of mail2.php:

-----------
<?php
if ($_REQUEST["Submit"]) {
header("Location:confirmation.php");
$Email = $_REQUEST['Email'] ;
mail("me@me.com", "Newsletter", "From:$Email");
}
else {
}
?>
-------------

I really hope that someone can help me out, as I'm about to go crazy with this.... ;-)

Thanks in advance!

Sofia

sofia

2:27 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



Well, I seem to have finally found a way around it with the include function (wish I had thought of that sooner!).

But if anyone can explain me why my attempts with header() were failing, I'd love to understand it...

storevalley

2:38 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



Headers really do have to be sent before anything else ... if the function was not right at the top of your page (before the first HTML tag) you'll get this kind of problem.

Even spaces that exist before the header output code will cause this kind of error.

sofia

12:48 am on Dec 13, 2004 (gmt 0)

10+ Year Member



Thanks a lot for the help!

I actually realised later that my include wasn't working that well, since my original page was now just further down the page...

Anyhow, I gave it a last shot with the header(), and it now works! HURRAY!
Yep! There mustn't be anything before allright... I just never imagined that that included the DTD as well...

I'm a lot smarter now :)

Adrian2k4

7:57 am on Dec 13, 2004 (gmt 0)

10+ Year Member



if you have problems with sending the header first, try output buffering:
[php.net...]
regards
adrian