I have an index form that submits an email to a page called thanks.php3. After thanks.php3 inserts the email into a text file, I would like to redirect the thanks page to another page in a different directory.
Unfortunately when I try using the $redirect command I receive the following error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/hearnofg/public_html/temp/news/thanks.php3:2) in /home/hearnofg/public_html/temp/news/thanks.php3 on line 22
The script I am using is as follows:
<html><head><title>Thanks!</title></head><body>
<?
$Body = file_get_contents("data/autoresponder.txt");
mail("$Email","Welcome to Heartland's Mailing list!",
"$Body","From: Rick\nReply-To: rick@rickclark.com");
$myfile = file("data/newsletter.txt");
$fh = fopen("data/newsletter.txt","w");
for ($index=0; $index < count($myfile); $index++)
{
if ($Email != chop($myfile[$index]))
{fputs($fh,$myfile[$index]);}
}
fputs($fh,$Email."\n");
fclose($fh);
[B]$redirect = true;
if ($redirect) {
header ("Location: ../forms/thanks.php");
exit;
}[/B]
?>
</body>
</html>
How can I redirect this page to ../forms/thanks.php ?