tags:

views:

23

answers:

1

Hi,

I get a strange error after submitting a form the error is this one:

        Warning: Cannot modify header information - headers already sent by 
        (output started at
        /var/www/g35003/coldcharlie.nl/subdomains/test/mailer.php:6) in 
        /var/www/g35003
        /coldcharlie.nl/subdomains/test/mailer.php on line 96

Line 96 contains this

// delete the cookie so it cannot sent again by refreshing this page
    setcookie('tntcon','');

This is the complete mailer.php

// ----------------------------------------- 
//  The Web Help .com
// ----------------------------------------- 
// remember to replace [email protected] with your own email address lower in this code.

// load the variables form address bar
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$verif_box = $_POST["verif_box"];

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$from = stripslashes($from); 

// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
    // if verification code was correct send the message and show this page
    mail("[email protected]", 'Online Formulier: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
    // delete the cookie so it cannot sent again by refreshing this page
    setcookie('tntcon','');
} else if(isset($message) and $message!=""){
    // if verification code was incorrect then return to contact page and show error
    header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
    exit;
} else {
    echo "no variables received, this page cannot be accessed directly";
    exit;
    }
?>

This is the head section of my mailer.php

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Computerhulp voor Particulieren en MKB in Leeuwarden en de rest van Friesland" />
    <meta name="keywords" content="computerhulp in friesland, pc service, Leeuwarden, Sneek, Drachten, Heerenveen, Bolsward, Buitenpost, Franeker, Gorredijk, Dokkum, Joure, Oosterwolde, Koudum, Harlingen " />
    <title>Computer stuk? Computerhulp nodig? Friese Computer Service - Leeuwarden, Sneek, Drachten, Heerenveen, Bolsward, Buitenpost, Franeker, Gorredijk, Dokkum, Joure, Oosterwolde, Koudum, Harlingen, Computerhulp Friesland</title>
    <link rel="bookmark" href="/favicon.ico" />
    <link rel="shortcut icon" href="/favicon.ico" />

    <link href="http://www.coldcharlie.nl/test/css/style.css" rel="stylesheet" type="text/css" />
  </head>
+1  A: 

Modifying the HTTP header is only possible if it was not sent to the client yet. And that takes place when you print something out.

And in your case the output starts at the line 6 in your mailer.php file. You can use the output buffer functions and buffer the output to avoid that.

Gumbo
I'm sorry, but that's way over my head. I hate this, but I have posted (edited) the whole header of my mailer.php in my question
Chris
@Chris: Just start `ob_start` before any output was done and it should work.
Gumbo
Great, I got it, I had to apply the php code before all the html indeed.
Chris