I'm trying to have my contact form redirect aftering it gets mailed. But I'm running into the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home3/ettrick/public_html/test3/mail.php:12) in /home3/ettrick/public_html/test3/mail.php on line 80
<?php
$email_message .= "Name: ".($name)."\n";
$email_message .= "Email: ".($email)."\n";
$email_message .= "Message: ".($message)."\n";
mail($ToEmail, $EmailSubject, $email_message, $mailheader);
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_from = "newsletter@kingdomhearts7.com";
$email_to = "fritzgattereau@gmail.com";
$email_subject = "Contact Form";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
if(mail){
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
else {
echo "There's been an error. Please try again.";
}
?>
<?php
}
?>
<?php
header( 'Location: http://kingdomhearts7.com/test3' ) ;
?>
I would really appreciate it if someone would help me out as I am a complete noob at php.
Thanks.
UPDATE: I was able to fix the headers error by removing some whitespace, but now I ran into a new problem.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in >>/home3/ettrick/public_html/test3/mail.php on line 28
<?php
$email_message .= "Name: ".($name)."\n";
$email_message .= "Email: ".($email)."\n";
$email_message .= "Message: ".($message)."\n";
mail($ToEmail, $EmailSubject, $email_message, $mailheader);
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_from = "newsletter@kingdomhearts7.com";
$email_to = "fritzgattereau@gmail.com";
$email_subject = "Contact Form";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n"
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
if(mail){
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
else {
echo "There's been an error. Please try again.";
}
?>
<?php
}
?>
<?php
header( 'Location: http://kingdomhearts7.com/test3' ) ;
?>