header (Location:) help not working

hi this is a copy of my code am trying to get it to redirect to the thankyou page but it just sits at a blank screen otherwise it all works. Am i putting the header line in the wrong place ifso where do i put it or whats going on please. i have changed the php to ph incase.

mailer <?ph $myemail = "[email protected]";

if(isset($_POST[‘Submit’])) {
$subject = “Registration Form”;
$name = check_input($_POST[‘Name’]);
/* check email address is valid */
$email = check_input($_POST[‘Email’], “Please enter your email address”);
if (!preg_match("/([\w-]+@[\w-]+.[\w-]+)/",$email))
{
show_error(“E-mail address not valid”);
}

$Questions = check_input($_POST[‘Questions’]);
$message = “Hello!\n Your registration form has been sent by:\n Name: $name \n Email: $email \n Qestions: $Questions\n”;
}
/* Initialise and Send email */
ini_set (“SMTP”,“something.something”);
ini_set (“sendmail_from”,"$email");
mail($myemail,$subject,$message);
header(“Location:thankyou.html”);
exit;

/* Our Functions
Check input for malicious code */

function check_input($data, $problem= ‘’)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_eror($problem);
}
return $data;
}
function show_error($myError)
{
?>

<b>Please correct the following error:</b><br />
<?ph echo $myError; ?>
<?ph exit(); } ?> any help please as i cant see what the problem is.
<?ph $myemail = "[email protected]"; if(isset($_POST['Submit'])) { $subject = "Registration Form"; $name = check_input($_POST['Name']); /* check email address is valid */ $email = check_input($_POST['Email'], "Please enter your email address"); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { show_error("E-mail address not valid"); } $Questions = check_input($_POST['Questions']); $message = "Hello!\n Your registration form has been sent by:\n Name: $name \n Email: $email \n Qestions: $Questions\n"; } /* Initialise and Send email */ ini_set ("SMTP","something.something"); ini_set ("sendmail_from","$email"); mail($myemail,$subject,$message); header("Location:thankyou.html"); exit; /* Our Functions Check input for malicious code */ function check_input($data, $problem= '') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_eror($problem); } return $data; } function show_error($myError) { ?>
<b>Please correct the following error:</b><br />
<?ph echo $myError; ?>
<?ph exit(); } ?>

you lacked letter P at the <?php

thankyou for your reply Hanaya,

as stated in the beginning of my message i removed the p from php incase it was against forum rules. this script does have the p in php when it runs. but still the header wont redirect. so my question still remains and any help would be apprieciated.

Soleous75, there should be no any output to browser before the header() function call. But in your code you send to browser all the html tags like … and then attempting to send headers (redirect) to a browser.
Basicaly, you need to restructure your code so that it either shows some error message on this page OR redirects to another page. You cannot at the same time display page and send redirection command using header(). Redirects from a html page could be made using javascript or meta refresh tags, if needed.

Sponsor our Newsletter | Privacy Policy | Terms of Service