I am trying to code an all in one HTML/PHP contact from with error checking. When I load this file in my browser there is not HTML. I am a newb php programmer so most likely forgot something pretty obvious.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>All In One Feedback Form</title>
</head>
<body>
<?
$form_block = "
<input type=\"hidden\" name=\"op\" value=\"ds\">
<form method=\"post\" action=\"$server[PHP_SELF]\">
<p>Your name<br />
<input name=\"sender_name\" type=\"text\" size=30 value=\"$_POST[sender_name]\" /></p>
<p>Email<br />
<input name=\"sender_email\" type=\"text\" size=30 value=\"$_POST[sender_email]\"/></p>
<p>Message<br />
<textarea name=\"message\" cols=30 rows=5 value=\"$_POST[message]\"></textarea></p>
<input name=\"submit\" type=\"submit\" value=\"Send This Form\" />
</form>";
if ($_POST[op] != "ds") {
//they see this form
echo "$form_block";
} else if ($_POST[op] == "ds") {
if ($_POST[sender_name] == "") {
$name_err = "Please enter your name<br>";
$send = "no";
}
if ($_POST[sender_email] == "ds") {
$email_err = "Please enter your email<br>";
$send = "no";
}
if ($_POST[message] == "ds") {
$message_err = "please enter message<br>";
$send = "no";
}
if ($send != "no") {
//its ok to send
$to = "[email protected]";
$subject = "All in one web site feed back";
$mailheaders = "From: website <some email [email protected]> \n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";
$msg = "Email sent from this site www.ccccc.com\n";
$msg .= "Senders name: $_POST[senders_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
mail($to, $subject, $msg, $mailheaders);
echo "<p>Mail has been sent</p>";
}
else if ($send == "no") {
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?>
</body>
</html>
FYI I am trying the example from a book named PHP 6 Fast and Easy Wed Development
UPDATE!!!
The code I see via view source is this.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>All In One Feedback Form</title>
</head>
<body>
<input type="hidden" name="op" value="ds">
<form method="post" action="">
<p>Your name<br />
<input name="sender_name" type="text" size=30 value="" /></p>
<p>Email<br />
<input name="sender_email" type="text" size=30 value=""/></p>
<p>Message<br />
<textarea name="message" cols=30 rows=5 value=""></textarea></p>
<input name="submit" type="submit" value="Send This Form" />
</form></body>
</html>