I have a php file that submits a form. I type into the index.html, and then it send the info to email.php. I am trying to redirect back to index.html after the form is submitted but I am getting the error: "Warning: Cannot modify header information - headers already sent by"
I have tried using header("Location:http://www.mywebpage.com/index.html");
at every different line of the php file and it hasn't worked. Below is my code. Any ideas?:
<?php
$filename = "email.csv";
$exists = (file_exists($filename));
$handle = fopen($filename, 'a');
$msg = "Thank you for your appointment.\n";//EMail message
$stringToAdd=""; //File into
if (!$exists){
foreach($_POST as $name => $value) {
$stringToAdd.="$name,";
}
$stringToAdd.="\n";
$new=False;
fwrite($handle, $stringToAdd);
}
$stringToAdd="";
foreach($_POST as $name => $value) {
print "$name : $value<br>";
$msg .="$name : $value\n";
$stringToAdd.="$value,";
}
$stringToAdd.="\n";
fwrite($handle, $stringToAdd);
//now close the file
fclose($handle);
$to = $_POST["uniqname"]."@tobey.com";
$headers = "From: ". "UMSI CDO" ."<umsi.careers@tobey.com>\r\n";
mail($to, 'Appointment Scheduled', $msg, $headers); // 'Appointment Scheduled' is the subject
echo "Email sent";
?>