PDA

View Full Version : PHP Contact Us Headers problem



Mounta1nGoat
16-11-2009, 08:32 PM
I coded this with the help of a tutorial and I changed a few things around but now recieve this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/mounta1n/public_html/PHP/sendmail.php:18) in /home/mounta1n/public_html/PHP/sendmail.php on line 51



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<form method="post" action="sendmail.php"><h1>Contact Us</h1>
<p>Email:
<input name="email" type="text" />
<br />
Subject:
<input type="text" name="title" />
<br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea>
<br />
<input type="submit" />
</p>
</form>
</div>
<div id="banner"></div>
</body>
</html>
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$title = $_REQUEST['title'] ;

if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {
?>
<html>
<head><title>Excuse me,</title></head>
<body>
<h1>Nice try,</h1>
<p>
But no.
</p>
</body>
</html>
<?php
}
if (!isset($_REQUEST['email'])) {
header( "Location: http://www.example.com/feedback.html" );
}
elseif (empty($email) || empty($message)) {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<form method="post" action="sendmail.php"><h1>Contact Us</h1><br />
<h6>Oops you missed something, try again.</h6>
<p>Email:
<input name="email" type="text" />
<br />
Subject:
<input type="text" name="title" />
<br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea>
<br />
<input type="submit" />
</p>
</form>
</div>
<div id="banner"></div>
</body>
</html>
<?php
}
else {
mail( **********@*******.co.uk, "Mounta1nGoat.co.uk Title: $title",
$message, "From: $email" );
header( "Location: http://www.mounta1ngoat.co.uk/PHP/thanks.html" );
}
?>


Could somebody help out please?

Jamesy
16-11-2009, 08:43 PM
header( "Location: http://www.mounta1ngoat.co.uk/PHP/thanks.html" );

has to be above the <head></head> tags

Mounta1nGoat
16-11-2009, 08:47 PM
Sorry but where exactly above the head tags? This is my first time coding something that actually works in PHP...

jacko2244
16-11-2009, 09:08 PM
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>

thats where the head tags are.

Tomm
17-11-2009, 05:07 PM
Actually it should be before ANY text, whitespace, or anything that outputs to the browser.



header( "Location: http://www.mounta1ngoat.co.uk/PHP/thanks.html" );

has to be above the <head></head> tags

Want to hide these adverts? Register an account for free!