Im trying to get my email form to work and it sends messages like it should, but instead of being redirected to my thank you page I keep getting this error message.
"Warning: Cannot modify header information - headers already sent by (output started at /home/hella/public_html/contact.php:4) in /home/hella/public_html/contact.php on line 39"
This is the entire script I'm using for my form mailer, any help would be greatly appreciated thank you!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css"/>
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css"/>
<font face="Arial, Helvetica, sans-serif">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Contact Form</title>
</head>
<?
$name = $_POST['name'];
$email = $_POST['email'];
// chnage this to the email you want the message to be sent to
$email2 = "[email protected]";
$subject = $_POST['subject'];
$message = $_POST['message'];
$submit = $_POST['submit'];
// change this to the subject you want your sender to see in their auto-response
$subject1 = "Thank You for Contacting Us";
// change to From Name<from@email>
$headers2 = "From: domain Inc<[email protected]>\r\n";
$headers2 .= "Content-type: text/html";
$headers = "From: $name<$email>\r\n";
$headers .= "Content-type: text/html";
// change to the html template you want to receive
$message1 = "Hey!<br><br>$name sent you an email on your website!<br><br>Submitted Info:<br>
Name: $name<br>Email: $email<br>Subject: $subject<br>Message: $message";
// change to the html template you want the sender to receive
$message2 = "Thank you for contacting us.<br>We will respond to you as soon as possible.<br><br>Thanks,<br>My Site";
if ($submit=="Send"){
// send to the sender
mail($email, $subject1, $message2, $headers2);
// send to the webmaster
mail($email2, $subject, $message1, $headers);
// redirect to thank you page
header("Location: http://domain/thankyou.php");
} else {
// display the form
echo'<body>
<h1>Contact Us</h1>
Use the form below to contact us. Please note that fields marked with a <font color="#FF0000">*</font> are required.<br /><br />
<form atcion="" method="post">
<span id="sprytextfield1">
<font color="#FF0000"> * </font>Your Name: <input type="text" name="name" /> <br />
<span class="textfieldRequiredMsg">You must enter yout Name.</span></span>
<span id="sprytextfield2">
<font color="#FF0000"> * </font>Your Email: <input type="text" name="email" /> <br />
<span class="textfieldRequiredMsg">You must enter your Email address.</span></span>
<span id="sprytextfield3">
<font color="#FF0000"> * </font>Subject of Message: <input type="text" name="subject" /> <br />
<span class="textfieldRequiredMsg">You must enter a Subject for this message.</span></span>
<span id="sprytextarea1">
<font color="#FF0000"> * </font>Message: <textarea name="message" rows="10" cols="30"></textarea><br /><br />
<span class="textareaRequiredMsg">You must enter your Message.</span></span>
<input type="submit" name="submit" value="Send" />
</form>
</body>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
//-->
</script>
</html>';
}
?>
"Warning: Cannot modify header information - headers already sent by (output started at /home/hella/public_html/contact.php:4) in /home/hella/public_html/contact.php on line 39"
This is the entire script I'm using for my form mailer, any help would be greatly appreciated thank you!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css"/>
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css"/>
<font face="Arial, Helvetica, sans-serif">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Contact Form</title>
</head>
<?
$name = $_POST['name'];
$email = $_POST['email'];
// chnage this to the email you want the message to be sent to
$email2 = "[email protected]";
$subject = $_POST['subject'];
$message = $_POST['message'];
$submit = $_POST['submit'];
// change this to the subject you want your sender to see in their auto-response
$subject1 = "Thank You for Contacting Us";
// change to From Name<from@email>
$headers2 = "From: domain Inc<[email protected]>\r\n";
$headers2 .= "Content-type: text/html";
$headers = "From: $name<$email>\r\n";
$headers .= "Content-type: text/html";
// change to the html template you want to receive
$message1 = "Hey!<br><br>$name sent you an email on your website!<br><br>Submitted Info:<br>
Name: $name<br>Email: $email<br>Subject: $subject<br>Message: $message";
// change to the html template you want the sender to receive
$message2 = "Thank you for contacting us.<br>We will respond to you as soon as possible.<br><br>Thanks,<br>My Site";
if ($submit=="Send"){
// send to the sender
mail($email, $subject1, $message2, $headers2);
// send to the webmaster
mail($email2, $subject, $message1, $headers);
// redirect to thank you page
header("Location: http://domain/thankyou.php");
} else {
// display the form
echo'<body>
<h1>Contact Us</h1>
Use the form below to contact us. Please note that fields marked with a <font color="#FF0000">*</font> are required.<br /><br />
<form atcion="" method="post">
<span id="sprytextfield1">
<font color="#FF0000"> * </font>Your Name: <input type="text" name="name" /> <br />
<span class="textfieldRequiredMsg">You must enter yout Name.</span></span>
<span id="sprytextfield2">
<font color="#FF0000"> * </font>Your Email: <input type="text" name="email" /> <br />
<span class="textfieldRequiredMsg">You must enter your Email address.</span></span>
<span id="sprytextfield3">
<font color="#FF0000"> * </font>Subject of Message: <input type="text" name="subject" /> <br />
<span class="textfieldRequiredMsg">You must enter a Subject for this message.</span></span>
<span id="sprytextarea1">
<font color="#FF0000"> * </font>Message: <textarea name="message" rows="10" cols="30"></textarea><br /><br />
<span class="textareaRequiredMsg">You must enter your Message.</span></span>
<input type="submit" name="submit" value="Send" />
</form>
</body>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
//-->
</script>
</html>';
}
?>