Im having trouble doing a self processing email form. First the errors display before any information has been entered. Second I get This error when the form is submitted:
Warning: Cannot modify header information - headers already sent by (output started at C:\Domains\sousaink.com\wwwroot\pennyspder\email.php:9) in C:\Domains\sousaink.com\wwwroot\pennyspder\email.php on line 37
However the form does send just doesnt redirect.
here is the html and PHP code, Please help, Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to Penny and Spder's Site</title>
<link rel="stylesheet" type="text/css" href="PennySpder.css" />
</head>
<body>
<table id="maintable" cellpadding="0" cellspacing="0">
<tr>
<td><a href="index.php"><img src="images/title_2.jpg" border="0" alt="Penny & Spder" /></a></td>
<td><img src="images/title_1.jpg" alt="Taughannock Falls, Ithaca N.Y." /></td>
</tr>
<tr>
<td colspan="2"><? include("navigation.html"); ?></td>
</tr>
<tr>
<td colspan="2"><table cellpadding="0" cellspacing="0">
<tr>
<td id="welcomeText"><p> </p>
<p><b><u>Email Us:</u></b></p>
<?
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$comments = stripslashes($comments);
$body = "$name\n$email\n$subject\n$comments";
$headers = "From: $name <$email>";
if (empty($name)) {
echo "You must enter your name";
} elseif (check_email_address($email)) {
mail('antoni@sousaink.com',$subject,$body,$headers);
header("location:http://as.sunyorange.edu/~int007/index.html");
} else {
echo "You must enter a valid email address";
}
?>
<form action="email.php" method="post">
<table align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="name" size="20" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" size="20" /></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subject" size="20" /></td>
</tr>
<tr>
<td colspan="2">Comments:</td>
</tr>
<tr>
<td colspan="2"><textarea name="comments" rows="5" cols="25"></textarea>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" /></td>
<td><input type="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form></td>
<td id="externalLinks"><? include("exlinks.html"); ?></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
<p id="footerlinks">
<? include("footerlinks.html"); ?>
</p>
<p> </p>
<script type="text/javascript" src="poppic.js"></script>
<?
//validate email address
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
?>
</body>
</html>
Thanks Again!