Jump to content

Bad header error


loquela

Recommended Posts

Hi there,

 

I'm new here and this is my first cry for help.

I have a simple send mail script that is causing an internal error.

 

I had exactly the same script on another server and it worked perfectly. I think the reson it is not working is because the new server runs php as cgi (have had other problems with very simple scripts working on the previous server but not on the new one) but I am not sure.

 

************************Problem code*********************

<?php

ini_set('arg_separator.output','&');

 

 

$enq=$_POST['enquiry_type'];

$name=$_POST['name'];

$org=$_POST['organisation'];

$sch=$_POST['school'];

$lea=$_POST['lea'];

$email=$_POST['email'];

$tel=$_POST['tel'];

$fax=$_POST['fax'];

$prod=$_POST['product'];

$msg=$_POST['msg'];

$pcms=$_POST['primary_cms'];

$scms=$_POST['secondary_cms'];

 

 

 

$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";

mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

 

mail('[email protected]',

 

/* Subject */ 'Educational Web Design - Web Enquiry',

 

"Enquiry Type: {$enq}\n

Name: {$name}\n

Organisation: {$org}\n

School:{$sch}\n

LEA: {$lea}\n

Email: {$email}\n

Telephone: {$tel}\n

Fax: {$fax}\n

Product: {$prod}\n

Message: {$msg}\n

Primary CMS Demo: {$pcms}\n

Secondary CMS Demo: {$scms}\n

",

 

"From: {$email}");

print "Content-type: text/html\n\n";

?>

************************************************

 

This processes information from the form page and is places at the very start of the process page before any of the HTML. The emails seem to be getting sent but I get the internal error befor the HTML is displayed.

 

The error from the server log is:

 

[Wed Feb 28 13:53:56 2007] [error] [client 213.123.204.143] malformed header from script. Bad header=/home/sites/educationaldesign.: confirm.php, referer: http://www.educationaldesign.co.uk/school_enquiry.php

 

 

Are there known issues with running php as cgi and what are the fixes?

 

PLEASE HELP

 

Simon

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/
Share on other sites

might want to break things up a bit to see what's going on

 

<?php
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];

$body = "Dear {$name}, \n\rThank you for your enquiry. \n\rYour message has been received by the Educational Web Design team. \n\rYou sould receive a responce within the next 48 hours.\n\r\n\rEducational Web Design.";

   mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

$subject = 'Educational Web Design - Web Enquiry';
$message = "Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n";

$headers = "From: {$email}\n\r";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail('[email protected]',$subject,$message,$headers);
?>

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197887
Share on other sites

Thanks guys,

 

print "Content-type: text/html\n\n";

 

This was added on somebody elses suggestion to fix the problem with the belo code.

 

This is the original that causes the internal error above.

 

<?php 
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];



$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";
   mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

mail('[email protected]', 

/* Subject */   'Educational Web Design - Web Enquiry',

"Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n
",

"From: {$email}");
?>

 

Ray, thanks. I tried your code and I get the same problem.  :'(

 

But this time the email comes with this at the top:

 

MIME-Version: 1.0

Content-Type: text/html; charset=ISO-8859-1

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197956
Share on other sites

Ray, I see what you've done. Again sorry.

 

I've confused everybody (and myself) with the print header rubbish :-[

 

Ok, my problem is with this:

 

<?php 
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];



$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";
mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

mail('[email protected]', 

/* Subject */	'Educational Web Design - Web Enquiry',

"Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n
",

"From: {$email}");

?>

 

As far as I can tell it is perfectly valid and pretty simple. And it worked on my previous server.

But now on this new server (hosting company) I get the internal error. The above code appears just before the html dtd and header.

 

Thanks in advance.

 

Simon

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197964
Share on other sites

Only took 2 minutes try this please cheers.

 

<?php 
ini_set('arg_separator.output','&');

$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];

$to = '[email protected]';

$subject = 'Educational Web Design - Web Enquiry';

$message = 'Dear '.$name.', \nThank you for your enquiry. \nYour message has been received by the Educational 
Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.
<br><br>
Enquiry Type: '.$enq.' \n
Name: '.$name.' \n
Organisation:  '.$org.' \n
School: '.$sch.' \n
LEA:  '.$lea.' \n
Email:  '.$email.' \n
Telephone:  '.$tel.' \n
Fax:  '.$fax.' \n
Product:  '.$prod.' \n
Message:  '.$msg.' \n
Primary CMS Demo:  '.$pcms.' \n
Secondary CMS Demo:  '.$scms.' \n
';

$headers = "From: $email\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
if(mail($to, $subject, $message, $headers)){

echo "mail sent";

}else{

echo"no mail sent";
} 

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197969
Share on other sites

Excellent!

No that is showing some progress. But there are still problems.

 

The mail is getting sent and we are getting the html page without the internal error.

But two more problems:

 

1. The html page is misfigured due to the printing of 'mail sent'

 

2. the send mail doesn't include the data:

 

Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design. 

Enquiry Type: School \n Name: Contact name here \n Organisation: \n School: School name here \n LEA: LEA name or code \n Email: Contact email address \n Telephone: \n Fax: \n Product: \n Message: Please type your message or enquiry here. \n Primary CMS Demo: \n Secondary CMS Demo: \n 

 

Are we getting somewhere?

 

Thanks again.

 

Simon

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197974
Share on other sites

Try this ok the mail will get sent and the page should go blank but the recever should get every think tell me.

<?php 
ini_set('arg_separator.output','&');

$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];

$to = '[email protected]';

$subject = 'Educational Web Design - Web Enquiry';

$message = 'Dear '.$name.', \nThank you for your enquiry. \nYour message has been received by the Educational 
Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.
<br><br>
Enquiry Type: '.$enq.' \n
Name: '.$name.' \n
Organisation:  '.$org.' \n
School: '.$sch.' \n
LEA:  '.$lea.' \n
Email:  '.$email.' \n
Telephone:  '.$tel.' \n
Fax:  '.$fax.' \n
Product:  '.$prod.' \n
Message:  '.$msg.' \n
Primary CMS Demo:  '.$pcms.' \n
Secondary CMS Demo:  '.$scms.' \n
';

$headers = "From: $email\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
mail($to, $subject, $message, $headers);

?>

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-197983
Share on other sites

Hi!

 

I tried your script

 

<?php 
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];



$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";
mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

mail('[email protected]', 

/* Subject */	'Educational Web Design - Web Enquiry',

"Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n
",

"From: {$email}");

?>

 

And it worked. You don't have to use any header for mail, because it is a plain text mail (you don't use any HTML character in your mail message) and you can send it like this.

Maybe the problem is that PHP is installed as CGI, but I don't know nothing about it. Why don't you copy the start of your HTML header here? Maybe you made a mistake in your HTML. I don't know! I just know that the above code is good and working. I tried it! But I have PHP installed as Apache.

 

 

All the best,

Adika

 

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-198049
Share on other sites

Thanks Adika,

 

I don't actually want to send any headers in the mail. I confused everybody with my first post by leaving a line in that shouldn't be there.

 

The code seems to be perfectly valid and did work on my last server that ran php as an apache module.

I just want to know why this doesn't work on my new server that is using php as cgi.

Does anybody have any ideas?

 

???

 

Simon

 

 

 

 

<?php 
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];



$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";
mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

mail('[email protected]', 

/* Subject */	'Educational Web Design - Web Enquiry',

"Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n
",

"From: {$email}");

?>

 

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-198590
Share on other sites

Here is the php plus the start of the HTML:

 

<?php 
ini_set('arg_separator.output','&');


$enq=$_POST['enquiry_type'];
$name=$_POST['name'];
$org=$_POST['organisation'];
$sch=$_POST['school'];
$lea=$_POST['lea'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$fax=$_POST['fax'];
$prod=$_POST['product'];
$msg=$_POST['msg'];
$pcms=$_POST['primary_cms'];
$scms=$_POST['secondary_cms'];



$body= "Dear {$name}, \nThank you for your enquiry. \nYour message has been received by the Educational Web Design team. \nYou sould receive a responce within the next 48 hours.\n\nEducational Web Design.";
mail($email, 'Thank you for your Enquiry', $body, 'From: [email protected]');

mail('[email protected]', 

/* Subject */ 'Educational Web Design - Web Enquiry',

"Enquiry Type: {$enq}\n
Name: {$name}\n
Organisation: {$org}\n
School:{$sch}\n
LEA: {$lea}\n
Email: {$email}\n
Telephone: {$tel}\n
Fax: {$fax}\n
Product: {$prod}\n
Message: {$msg}\n
Primary CMS Demo: {$pcms}\n
Secondary CMS Demo: {$scms}\n
",

"From: {$email}");



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml"
             xml:lang="en">
<head>
<title>School Contact</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="title" content="Enquiry confirmation page" />
<meta name="author" content="Educational Web Design Limited" />
<meta name="description" content="Page confirming receipt of online enquiry" />
<meta name="keywords" content="online enquiry, confirmation" />
</head>

<body>

 

The emails are getting sent, but the html page is not getting displayed because of an internal error:

 

malformed header from script. Bad header=/home/sites/educationaldesign.: process.php, referer: http://www.educationaldesign.co.uk/school_enquiry.php

 

I know the script should work because it did on the previous server and Adika has confirmed that it works.

I'm guessing it must be to do with php being run as cgi. But what am I missing? Do I need to add something?

 

I'm pulling my hair out here!  :'(

Link to comment
https://forums.phpfreaks.com/topic/40868-bad-header-error/#findComment-198883
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.