Contact Form problem - Headers already sent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Contact Form problem - Headers already sent

Post by Sindarin »

Code: Select all

<?
 
/*
 
 
Contact form
 
 
*/
 
//setup recipient email
$form_to='mymail@mysite.com';
$form_from='mymail@mysite.com';
 
//Get the variables from the form
 
$form_name=$_POST['form_name'];
$form_tel=$_POST['form_tel'];
$form_efoa=$_POST['form_efoa'];
$form_sbae=$_POST['form_sbae'];
$form_mona_andron=$_POST['form_mona_andron2'];
$form_dipla_andron=$_POST['form_dipla_andron2'];
$form_mona_andron35=$_POST['form_mona_andron352'];
$form_mona_andron50=$_POST['form_mona_andron502'];
$form_mona_gynaikon=$_POST['form_mona_gynaikon2'];
$form_dipla_gynaikon=$_POST['form_dipla_gynaikon2'];
$form_mona_gynaikon35=$_POST['form_mona_gynaikon352'];
$form_mona_gynaikon50=$_POST['form_mona_gynaikon502'];
$form_agree=$_POST['form_agree'];
 
if ($form_agree=="")
{
//user not agreed
header ('Location: http://www.mysite.com/participate-agreefailure.php');
die("");
}
 
if ($form_name=="" || $form_tel=="")
{
//name & tel not filled
header ('Location: http://www.mysite.com/participate-failure.php');
die("");
}
 
//setup the email message
 
$email_subject="User Registration";
$email_message="<font family='Arial'><b>??? ???????</b><br/><br/>
?????????????: <b>$form_name</b><br/>
????????: <b>$form_tel</b><br/>
????: <b>$form_efoa</b><br/>
????: <b>$form_sbae</b><br/><hr><br/>
<br/><b>????????? [on=???]</b><br/>
???? ??????: <b>$form_mona_andron</b><br/>
????? ??????: <b>$form_dipla_andron</b><br/>
???? ?????? 35+: <b>$form_mona_andron35</b><br/>
???? ?????? 50: <b>$form_mona_andron50</b><br/>
???? ????????: <b>$form_mona_gynaikon</b><br/>
????? ????????: <b>$form_dipla_gynaikon</b><br/>
???? ????????: 35+: <b>$form_mona_gynaikon35</b><br/>
???? ???????? 50: <b>$form_mona_gynaikon50</b><br/>
</font>";
 
//send email
 
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "To: $form_to \r\n";
    $headers .= "From: $form_from";
mail( $form_to, $email_subject, $email_message, $headers);
 
//email sent, go to success page
header ('Location: http://www.mysite.com/participate-success.php');
 
 
?>
I am trying to create a registration form with some basic validation. Problem is that the page from where the form is submitted is encoded in utf-8. The form was working until I converted the document to utf-8, but otherwise the form doesn't work. What I do wrong?

The error it now outputs is:

Code: Select all

[b]Warning[/b]: Cannot modify header information - headers already sent by (output started at D:\Sites\mysite.com\send.php:1) in D:\Sites\mysite.com\send.php on line 34
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: Contact Form problem - Headers already sent

Post by mchaggis »

This usually happens to me when I have a space or blank line at the top off the file just before the opening <?, that would be the first place I'd look
generationgav
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 6:54 am

Re: Contact Form problem - Headers already sent

Post by generationgav »

If that doesn't work then try looking at
http://uk3.php.net/ob_start

Although looking at your code, it shouldn't be needed!
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Contact Form problem - Headers already sent

Post by Sindarin »

Odd, now it works... :/
Post Reply