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 = "[email protected]";


$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
https://forums.phpfreaks.com/topic/296900-php-headerredirect-help/
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.

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

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.