Reputation: 3
So I've tried publishing a page with PHP contact form on 2 different servers and I can't get either of them to work perfectly.
Server 1:
Returns a 500 internal error
page upon submission.
I contacted web support and they replied saying I have a:
malformed header from script 'index.php': Bad header:
My code for index.php as follows:
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="[email protected]";
$subject="test subject";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n";
$message="
Name:
$name
<br>
Email:
$email
<br>
Message:
$query
";
if(mail($to,$subject,$message,$headers))
header("Location:../contact.php?msg=Successful Submission!<br />
Thank you for contacting us.");
else
header("Location:../contact.php?msg=Error To send Email !");
}
?>
Server 2:
Links me to my "Thank you page" correctly, but it's showing
"Error To send Email !" instead of
"Successful Submission!"
Any help or advice will be greatly appreciated!
Upvotes: 0
Views: 327
Reputation: 7661
I think the propblem is in this part:
if(mail($to,$subject,$message,$headers))
header("Location:../contact.php?msg=Successful Submission!<br />
Thank you for contacting us.");
else
header("Location:../contact.php?msg=Error To send Email !");
Specificly in the header();
<br />
would suggest a file called ">Thank you for contacting us."Check out: http://www.w3schools.com/tags/ref_urlencode.asp;
Also put exit();
after each header to prevent futher execution of the script
Upvotes: 1
Reputation: 1802
The problem appears to be the header location redirect call which should provide a full url, e.g.:
header("Location: http://www.example.com");
Relative urls are processed as per the browser's best efforts and your browser clearly isn't liking the ../, hence the "bad header" complaint.
This is noted on the php.net page as per the official URL spec.
Upvotes: 1