We help IT Professionals succeed at work.

header problem

derrida
derrida asked
on
Medium Priority
349 Views
Last Modified: 2012-05-06
Hi
i have a contact form. when i send it i get:
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\or_02\contact.php:290) in C:\wamp\www\or_02\contact.php on line 376

this is the most basic things.
the code is attached.

best regards

ron
if(isset($_POST['submit'])){
$to = "me@gmail.com";
$subject = $_POST["email_subject"];
$message = $_POST["email_msg"];
$from = $_POST["email_email"];
$headers = "From: $from";
$domail = mail($to,$subject,$message,$headers);
 
if($domail){
	header('Location: contacthanks.php');
}else{
	echo "not ok";
}
 
}

Open in new window

Comment
Watch Question

Commented:
This error usually means that you have a blank line at the beginning of your script.  If so, remove it.
CERTIFIED EXPERT

Commented:
derrida,

what's the file type? plain text/UTF8 ?
if UTF8, it's mostly because of the byte order mark cause.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24037516.html
please read id 23333523
Commented:
The error tells you exactly where to start looking for the problem

 "(output started at C:\wamp\www\or_02\contact.php:290)"

Look on like 290 of contact.php. You will likely find that you have already sent something to the browser. This could simply be a blank line, or you may have already started sending output of some kind (i.e. HTML).

When redirecting a browser you need to make sure that any code that needs to determine if a redirect is in order is done before any HTML is sent. Or, you can use a buffer:

http://us.php.net/outcontrol
http://www.codewalkers.com/c/a/Miscellaneous/PHP-Output-Buffering/
 
 Although I would recommend correcting the problem rather than working around it by using buffering.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.