...

View Full Version : contact form error



tns123j
07-20-2008, 11:02 PM
I have a simple php form I've been using for client's contact pages for years. It's worked great, but something is wrong with it now. I get an error:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:9) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 47

LINE 47: header ('Location: http://www.alpineec.com/TEST/thank-you_02.php');

http://alpineec.com/TEST/contact.php


Any thoughts on how to fix it?


In the <head> tags:

<head>


<meta http-equiv="zrefresh" content="3">
<meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
<link rel="stylesheet" type="text/css" href="default.css" />

<?php
if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum

$message = NULL; // Variable to hold final error message if something is not filled out.

// Check if the name was entered.
if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
$name = TRUE;
} else {
$name = FALSE;
$message .= '<P>You forgot to enter your name!</p>';
}
// Check if the Return e-mail address was entered.
if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
// Check if the Subject is intact.
if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
$subject = TRUE;
} else {
$subject = FALSE;
$message .= '<p>You forgot to enter a subject!</p>';
}
// Check if anything was entered into the body.
if(strlen($_POST['body']) > 0) { // if statment to check just like before
$body = TRUE;
} else {
$body = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
if($name && $email && $subject && $body) { // if everything was entered...
// Send the email
$headers = "From: {$_POST['name']}\r\n"; // Create a From part of the email
$headers .= "Reply-To: {$_POST['email']}\r\n"; // Create the Reply-To so you can reply w/their email
mail ('jmulqueen@gmail.com', $_POST['subject'], $_POST['body'], $headers); // This will send the email
header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
exit();
} else {
$message .= '<p>Please try again.</p>';
}
}
?>

</head>


Actual form:

<?php
if (isset($message)) { // if there is an error, print them
echo '<font color="red">', $message,'</font>';
}
?>
</p> Questions or Comments? Send us an e-mail with the form below!<br />
<br />
<form method="POST" action="<?=$PHP_SELF?>">
<p>Name:
<input type="text" name="name" size="20">
<p> Email:&nbsp;
<input type="text" name="email" size="20">
<p>Subject<font size="2"></font>:
<input type="text" name="subject" size="70">
<br>
<font size="2"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></font> <br>
Comments or Questions:<br>
<br>
<textarea rows="8" name="body" cols="80"></textarea>
<br>
<input type="submit" name="submit" value="Send">
<input type="reset" value="Reset">
<br>
</form>

oesxyl
07-20-2008, 11:30 PM
move this part:


<head>


<meta http-equiv="zrefresh" content="3">
<meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
<link rel="stylesheet" type="text/css" href="default.css" />


after the '?>' and before this:


</p> Questions or Comments? Send us an e-mail with the form below!<br />
<br />
<form method="POST" action="<?=$PHP_SELF?>">


sorry, wrong message. correct is "move the part I said after '?>' and before '</head>'"
regards

tns123j
07-20-2008, 11:45 PM
Same error. Line 42 now...which is the same code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<?php
if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum

$message = NULL; // Variable to hold final error message if something is not filled out.

// Check if the name was entered.
if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
$name = TRUE;
} else {
$name = FALSE;
$message .= '<P>You forgot to enter your name!</p>';
}
// Check if the Return e-mail address was entered.
if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
// Check if the Subject is intact.
if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
$subject = TRUE;
} else {
$subject = FALSE;
$message .= '<p>You forgot to enter a subject!</p>';
}
// Check if anything was entered into the body.
if(strlen($_POST['body']) > 0) { // if statment to check just like before
$body = TRUE;
} else {
$body = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
if($name && $email && $subject && $body) { // if everything was entered...
// Send the email
$headers = "From: {$_POST['name']}\r\n"; // Create a From part of the email
$headers .= "Reply-To: {$_POST['email']}\r\n"; // Create the Reply-To so you can reply w/their email
mail ('jmulqueen@gmail.com', $_POST['subject'], $_POST['body'], $headers); // This will send the email
header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
exit();
} else {
$message .= '<p>Please try again.</p>';
}
}
?>
<head>
<meta http-equiv="zrefresh" content="3">
<meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
<link rel="stylesheet" type="text/css" href="default.css" />
</head>

oesxyl
07-21-2008, 12:08 AM
because is the same mistake:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


you can't put html code or print/echo anything before the line with the header.

regards

tns123j
07-21-2008, 12:12 AM
good to know...but same error!


<?php
if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum

$message = NULL; // Variable to hold final error message if something is not filled out.

// Check if the name was entered.
if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
$name = TRUE;
} else {
$name = FALSE;
$message .= '<P>You forgot to enter your name!</p>';
}
// Check if the Return e-mail address was entered.
if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
// Check if the Subject is intact.
if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
$subject = TRUE;
} else {
$subject = FALSE;
$message .= '<p>You forgot to enter a subject!</p>';
}
// Check if anything was entered into the body.
if(strlen($_POST['body']) > 0) { // if statment to check just like before
$body = TRUE;
} else {
$body = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
if($name && $email && $subject && $body) { // if everything was entered...
// Send the email
$headers = "From: {$_POST['name']}\r\n"; // Create a From part of the email
$headers .= "Reply-To: {$_POST['email']}\r\n"; // Create the Reply-To so you can reply w/their email
mail ('jmulqueen@gmail.com', $_POST['subject'], $_POST['body'], $headers); // This will send the email
header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
exit();
} else {
$message .= '<p>Please try again.</p>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

oesxyl
07-21-2008, 12:21 AM
good to know...but same error!
I'm glad, :)

this apply also to the files where this file is included, I mean before the line 'include(....)' you can't put html code or print/echo anything.

regards

tns123j
07-21-2008, 12:22 AM
The error is still there. Any thoughts?

oesxyl
07-21-2008, 12:26 AM
The error is still there. Any thoughts?
did you check files where is included?

regards

_Aerospace_Eng_
07-21-2008, 04:53 AM
That should be working. I suggest you remove your email address from your posts as well. Just went to your site and it appears to be working just fine.

tns123j
07-21-2008, 11:19 AM
everything is included. Try the form yourself. You'll see the error.

Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:2) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 40

oesxyl
07-21-2008, 11:51 AM
everything is included. Try the form yourself. You'll see the error.

Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:2) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 40
this file is ok, post the file where is the form.

regards

_Aerospace_Eng_
07-21-2008, 06:00 PM
Please post all of your code for contact.php

header calls MUST be before HTML output. There are ways to get around it but then thats just being lazy.

tns123j
07-22-2008, 12:46 AM
<?php
if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum

$message = NULL; // Variable to hold final error message if something is not filled out.

// Check if the name was entered.
if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
$name = TRUE;
} else {
$name = FALSE;
$message .= '<P>You forgot to enter your name!</p>';
}
// Check if the Return e-mail address was entered.
if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
// Check if the Subject is intact.
if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
$subject = TRUE;
} else {
$subject = FALSE;
$message .= '<p>You forgot to enter a subject!</p>';
}
// Check if anything was entered into the body.
if(strlen($_POST['body']) > 0) { // if statment to check just like before
$body = TRUE;
} else {
$body = FALSE;
$message .= '<p>You forgot to enter your e-mail address!</p>';
}
if($name && $email && $subject && $body) { // if everything was entered...
// Send the email
$headers = "From: {$_POST['name']}\r\n"; // Create a From part of the email
$headers .= "Reply-To: {$_POST['email']}\r\n"; // Create the Reply-To so you can reply w/their email
mail ('jmulqueen@gmail.com', $_POST['subject'], $_POST['body'], $headers); // This will send the email
header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
exit();
} else {
$message .= '<p>Please try again.</p>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<meta http-equiv="zrefresh" content="3">
<meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
<link rel="stylesheet" type="text/css" href="default.css" />
</head>
<body>

<div id="upbg"></div>

<div id="outer">


<div id="header">
<div id="headercontent">
<h2>&nbsp;</h2>
</div>
<img src="images/main_logo_noglow" alt="Alpine" width="700" height="150" /> </div>

<div id="menu">
<!-- HINT: Set the class of any menu link below to "active" to make it appear active -->
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="aboutus.php">About Us</a></li>
<li><a href="services.php">Services</a></li>
<li><a href="projects.php">Projects</a></li>
<li><a href="testimonials.php">Testimonials</a></li>
<li><a href="contact.php" class="active">Contact</a></li>
</ul>
</div>

<div id="content"><div id="normalcontent">
<div class="contentarea">
<!-- Normal content area start -->
<p id="style">
Alpine Environmental Consultants<br>
Suite G<br />
201 Ward St.<br />
Montgomery, NY 12549<br />
<br />
Phone: (845) 457-8141<br />
Fax:(845) 457-8763
<br />
<br /><iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=201+Ward+St.+Montgomery,+NY+12549&amp;sll=37.0625,-95.677068&amp;sspn=35.957999,84.199219&amp;ie=UTF8&amp;s=AARTsJq27qQ0kqbq6wHZDj4NpLDXbruzAg&amp;ll=41.534218,-74.226294&amp;spn=0.019275,0.025749&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe>
<br />
</p>
<?php
if (isset($message)) { // if there is an error, print them
echo '<font color="red">', $message,'</font>';
}
?>
</p> Questions or Comments? Send us an e-mail with the form below!<br />
<br />
<form method="POST" action="<?=$PHP_SELF?>">
<p>Name:
<input type="text" name="name" size="20">
<p> Email:&nbsp;
<input type="text" name="email" size="20">
<p>Subject<font size="2"></font>:
<input type="text" name="subject" size="70">
<br>
<font size="2"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></font> <br>
Comments or Questions:<br>
<br>
<textarea rows="8" name="body" cols="80"></textarea>
<br>
<input type="submit" name="submit" value="Send">
<input type="reset" value="Reset">
<br>
</form>
<!-- Primary content: Stuff that goes in the primary content column (by default, the left column) -->
</div>
</div>


<div id="primarycontainer"> </div>


<!-- Secondary content: Stuff that goes in the secondary content column (by default, the narrower right column) -->
</div>

<div id="footer">
<div class="left">
<?php include('./footer.php');?>
</div>
</div>
</div>

</body>

</html>

oesxyl
07-22-2008, 11:28 AM
replace this:

<?php
if (isset($message)) { // if there is an error, print them
echo '<font color="red">', $message,'</font>';
}
?>


with this:

<?php
<?php
if (isset($message) && !isset($_POST['submit'])) { // if there is an error, print them
echo '<font color="red">', $message,'</font>';
}
?>


regards

tns123j
07-23-2008, 01:34 AM
perfect. thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum