5 Replies - 271 Views - Last Post: 05 January 2013 - 07:30 PM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 11-December 11

Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 06:57 AM

my script

okey i have upload my site everything works just fine except my contact form
here's my code

FYI - Im very new to the php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

	$user_name = $_POST["NameBox"];
	$user_contact = null;
	$user_contact=$_POST["ContactBox"];
	$comment = $_POST["msgbox"];
	
	if($user_contact==null)
	{
		$user_contact = "Not provided";
		
	}
	
	
	$to = "mymail@domain.com";
	 $subject = "Message From Web";
	 $body = "Contact name is = $user_name | Contact number is = $user_contact | user comment is = $comment";
	 
	 mail($to, $subject, $body);
	 
	 header( 'Location:http://www.masconsolidated.com/confirmation.html');
	 
	 
?>
</body>
</html>


when i submit the form im getiing a error like

Warning: Cannot modify header information - headers already sent by (output started at /home/masconso/public_html/processData.php:10) in /home/masconso/public_html/processData.php on line 30

i can't figure it out..please help me
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Warning: Cannot modify header information - headers already sent by ..

#2 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 07:03 AM

Hey.

To quote the manual entry for header():

php.net said:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.


The header() function modifies the headers of the HTTP response. Once you start sending content - like you do in the very first lines of your code - then PHP has to send the headers to the browser first so it can start sending the body of the response. After that happens, you obviously can't edit the headers.

This post has been edited by Atli: 05 January 2013 - 07:04 AM

Was This Post Helpful? 2
  • +
  • -

#3 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 11-December 11

Re: Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 07:17 AM

View PostAtli, on 05 January 2013 - 07:03 AM, said:

Hey.

To quote the manual entry for header():

php.net said:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.


The header() function modifies the headers of the HTTP response. Once you start sending content - like you do in the very first lines of your code - then PHP has to send the headers to the browser first so it can start sending the body of the response. After that happens, you obviously can't edit the headers.


actually i dont understand :( can you give me a sample code or something :(
Was This Post Helpful? 0
  • +
  • -

#4 Slice  Icon User is offline

  • sudo pacman -S moneyz


Reputation: 239
  • View blog
  • Posts: 692
  • Joined: 24-November 08

Re: Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 08:43 AM

Headers can only be used when nothing has been sent to the browser. PHP code is executed server side, which means it is all executed before anything is sent to your web browser.

<?php

$x = $y + 3;

if($x == 3)
{
   header("location: index.php");
}

?>



In a file on it's own, this would work fine. You have code before your header, but nothing is outputted to the browser.

<?php
//This would produce your error
$x = $y + 3;

echo $x; //This is an output, and it occurs before the header call

if($x == 3)
{
   header("location: index.php");
}

?>



So when you have html and php mixed in one php file, your html is processed before the header call, is just the same as echoing out before the header.
Was This Post Helpful? 2
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 07:11 PM

View Postistore221, on 05 January 2013 - 10:17 AM, said:

actually i dont understand :(/> can you give me a sample code or something :(/>

Do you understand the difference between client and server, and the fact that PHP is server side and HTML is client side? Mixing the two languages in your file does not change this basic fact, and until you get this you're guaranteed to have problems.
Was This Post Helpful? 0
  • +
  • -

#6 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 11-December 11

Re: Warning: Cannot modify header information - headers already sent by ..

Posted 05 January 2013 - 07:30 PM

View PostCTphpnwb, on 05 January 2013 - 07:11 PM, said:

View Postistore221, on 05 January 2013 - 10:17 AM, said:

actually i dont understand :(/>/> can you give me a sample code or something :(/>/>

Do you understand the difference between client and server, and the fact that PHP is server side and HTML is client side? Mixing the two languages in your file does not change this basic fact, and until you get this you're guaranteed to have problems.


okey i separate the code . i removed all the html codes :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1