Jump to content

php header/redirect help


WarMacheen

Recommended Posts

I've been rearranging and changing things for a few hours and I can't get past this issue

 

Warning: Cannot modify header information - headers already sent by (output started at /****/****/****/****/php/mailer.php:1) in /****/****/****/****/php/mailer.php on line 27

 

If I comment out the thanks.html header there isn't an error, but the code also doesn't redirect to the correct html page. I've also verified that there isn't any white space issues at the beginning and end of the code block

<?php
$myemail = "abcd@abcd.org";


$first_name = check_input($_POST['first_name'], "Enter your first name");
$last_name = check_input($_POST['last_name'], "Enter your last name");
$subject = "email from Dulles ISAC contact form";
$email = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your message");


if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}


$message = "
First Name: $first_name
Lirst Name: $last_name
E-mail: $email
Comments: $comments
";

mail($myemail, $subject, $message);

header('Location:thanks.html');
exit();


function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>
Link to comment
Share on other sites

since the output, that's causing the problem, is occurring on line 1 of the file and the only php code on that line is the php tag, you either have something in the file before the php tag or your file has been saved with utf-8 encoding and the BOM (Byte Order Mark) characters by your editor.

 

insure that there's no characters before the first php tag and insure that your editor is saving the file without the BOM characters.

Link to comment
Share on other sites

since the output, that's causing the problem, is occurring on line 1 of the file and the only php code on that line is the php tag, you either have something in the file before the php tag or your file has been saved with utf-8 encoding and the BOM (Byte Order Mark) characters by your editor.

 

insure that there's no characters before the first php tag and insure that your editor is saving the file without the BOM characters.

The encoding was the problem, thank you. I changed to UTF-8 without signature, works

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.