The correctly working version can be found on contact.php (remove the "-problem" from the page url). The entire code is below, but the quick difference between the two pages is:
contact.php:
<form method="post" action="contact.php">
contact-problem.php:
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
I could simply just use the method that works, but I want to know why the broswer redirects to a place I have never mentioned in the code. It's as strange as getting spam eMails from people with the same name as your friends...as if someone knows what's in your address book.
Can you explain this phenomenom?
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>[SAH] Contact -- Shad A. Hall Gallery</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="Imagetoolbar" content="no" />
<link rel="stylesheet" href="sah-css.css" type="text/css" />
</head>
<body>
<div id="containermaster">
<div id="header">
<img src="images/sah-titlebar-768x112-g64.gif" width="768" height="112" alt="Title bar - Click to go to the main page" />
<img id="menu" src="images/sah-menu-768x17-g64.gif" width="768" height="17" alt="menu" usemap="#sah_menu_768x17_g64_Map" />
<map id="sah_menu_768x17_g64_Map" name="sah_menu_768x17_g64_Map">
<area shape="rect" alt="Contact" coords="198,0,242,15" href="contact.html" />
<area shape="rect" alt="About" coords="151,1,188,15" href="about.html" />
<area shape="rect" alt="Art Gallery" coords="117,1,140,15" href="gallery.html" />
<area shape="rect" alt="Home" coords="73,1,103,15" href="index2.html" />
</map>
</div><!-- end of header div //-->
<div id="left"></div>
<div id="content">
<img src="images/spacer.gif" width="1" height="30" alt="" />
<?php
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
{
//for now:
//get all the data from the form
$name= $_POST['name'];
$email = $_POST['email'];
$usersubject = $_POST['subject'];
$comment = stripslashes($_POST['comment']);
$from="me@myexamplesite.com"; //this is what will appear in the from part in your email
$errors = '';
if($name == '')
{
$error .= "<span class=\"error\">You must enter your <label for=\"name\">name</label>.</span><br />";
}
if($email == '')
{
$error .= "<span class=\"error\">You must enter an <label for=\"email\">e-mail</label> address.</span><br />";
}
elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$", $email)) //if email entered, verify format
{
$error .= "<span class=\"error\">Your <label for=\"email\">email</label> is not of valid format.</span><br />";
}
if($comment == '')
{
$error .= "<span class=\"error\">You must enter some <label for=\"comment\">comment</label>.</span><br />";
}
if($error == '') //If no errors
{
$sendTo = "SAH comment <me@myexamplesite.com>"; //this will be the address that the mail gets sent to
$subject = "Question from SAH Gallery";
$body = "You have received the following from the web based contact form:\r\n";
$body .= "---------------------------------------------------------------\r\n";
$body .= "Subject: Mail from Site\r\n";
$body .= "From: ".$name."\r\n";
$body .= "IP Address: ".$_SERVER['REMOTE_ADDR']."\r\n";
$body .= "Questions/comment:\r\n";
$body .= $comment ."\r\n";
$body .= "---------------------------------------------------------------\r\n";
$headers = 'From: '.$email."\r\n" .
'Reply-To: '.$email;
if(mail($sendTo, $subject, $body, $headers))
{
$success="<div class=\"error centertext\">Thank you for contacting me. I will respond soon.</div>";
$name='';
$email='';
$comment='';
}
else
{
$error = "<div class=\"error\"><span class=\"error\">Unfortunately, we were unable to send your e-mail. Please try again.</span></div>";
exit();
}
}
}
?>
<?php
if(!empty($error))
{
echo "<div class=\"error\">\n";
echo "<h4 style=\"font-family:12px verdana, garamond, sans-serif; color:red;\">Uh oh! An error occurred...</h4>";
echo $error;
echo "</div>\n";
}
if(!empty($success))
{
echo $success;
}
?>
<!--<form method="post" action="contact.php">-->
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<fieldset id="contact">
<legend id="legend">Contact Form:</legend>
<label for="name">Name:</label>
<input type="text" size="50" name="name" id="name" value="" maxlength="50" /><br />
<label for="email">Email:</label>
<input type="text" size="50" name="email" id="email" value="" maxlength="100" /><br />
<label for="comment">Questions/comment:</label><br />
<textarea name="comment" id="comment" cols="43" rows="4"></textarea>
<div class="input"><input type="submit" name="submit" value="Submit" /> <input type="reset" value="Reset" /></div>
</fieldset>
</form>
</div>
<div id="right"></div>
<div id="footer"></div>
</div><!-- end of container master div //-->
</body>
</html>
Creeped out,
Shad
P.s. I started this topic over here to see if I could get some fresh ideas and approaches on thoughts as why this might be happening. The other thread (mentioned above) posts answered the initial problem, but not what causes the issue. I also posted it here since it wouldn't be considered "double-posting"...not trying to be unethical here, just trying to get the most amount of people on it.