Jump to content

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( "brett.mcdaniel@ttu.edu", "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("brett.mcdaniel@ttu.edu", "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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.