Jump to content

Cannot modify header info


brmcdani

Recommended Posts

I am getting the following error message:

 

Cannot modify header information - headers already sent by (output started at /home/content/s/a/g/sagates/html/contact.php:1) in /home/content/s/a/g/sagates/html/contact.php on line 17

 

 

Here is my code:

 

<?php
ob_start();
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$pref = $_REQUEST['pref'];
$type = $_REQUEST['type'];
$kind = $_REQUEST['kind'];
$message = $_REQUEST['message'];
$body = "Name: $name
\nPhone Number: $phone
\nEmail: $email
\nContact Preference: $pref
\nJob Type: $type
\nInterested In: $kind
\nDescription: $message \n\n";
mail( "[email protected]", "Contact Request", $body);
header("Location: thankyou.htm");
?>

 

I think I need an ending ob_ statement just not sure which one.  Can someone please help me out??? Thanks

Link to comment
https://forums.phpfreaks.com/topic/186833-cannot-modify-header-info/
Share on other sites

The <?php must be the very first character of the file.

 

  <?php

 

Is not valid, that will cause a header message, as will:

 

<?php

 

The correct way is:

 

<?php

 

Notice no extra spaces etc. If it is not done that way correct it and it should work (without the ob_start / flush methods).

Ok there are no extra spaces anywhere with the starting php line now I have this and am getting a header error message on line 17 which is the beginning of the header line.

 

<?php
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$pref = $_REQUEST['pref'];
$type = $_REQUEST['type'];
$kind = $_REQUEST['kind'];
$message = $_REQUEST['message'];
$body = "Name: $name
\nPhone Number: $phone
\nEmail: $email
\nContact Preference: $pref
\nJob Type: $type
\nInterested In: $kind
\nDescription: $message \n\n";
mail("[email protected]", "Contact Request", $body);
header("Location: thankyou.htm");
?>

It could be how the file is being saved. Try opening a new page in notepad and pasting that code in there making sure there are no extra lines at the beginning and saving the file and see if it works then. As a BOF (beginning of file, at least I think that is what it is called) marker may have been added by your editor.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.