All in one - EMAIL FORM
Posted: Mon Apr 04, 2011 3:05 pm
Hi,
New to php and i'm working through exercises in a text book. I have finished the script, put it on my server, when I hit the Submit button I receive this message "Error 404: NOT FOUND!Your browser cannot find the document corresponding to the URL you typed in. ". After hitting the submit button, In my address bar it looks like it's trying to find a file named POST. After going through the code I can't figure out why it's looking for POST. (I only have this one file (allinone_form.php) on my server in a folder (phptext), I'm assuming I only need the one file considering it's an "all in one" form. Anyways, here is the code, could someone please help clarify what I have done wrong? It would really help to understand before I move on...
<? //Below I am putting the ENTIRE form into a variable called $form_block
/*When you use $_SERVER[PHP_SELF] as a form action, you're saying, "When
the submit button is clicked, reload this script and do something."
$_SERVER[php_self] has a value of the script's current name (allinone_form.php)
*/
$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<p><strong>Your Name:</strong><br />
<INPUT type=\"text\" NAME= \"sender_name\" SIZE=30></p>
<p><strong>Your Email Address:</strong><br />
<INPUT type=\"text\" NAME=\"sender_email\" SIZE=30></p>
<p><strong>Message:</strong><br />
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></p>
</form>";
/*the 3 if statements below just make sure there's something in the appropriate fields*/
if ($_POST[op] != "ds"){
//this then shows the form...
echo "$form_block";
}else if ($_POST[op] == "ds") {
if ($_POST[sender_name] ==""){
$name_err = "<font color=red>You forgot to enter your name!</font><br />";
$send = "no";
}
if($_POST[sender_email] = "" ){
$email_err = "<font color=red>We need your email address dude.</font><br />";
$send = "no";
}
if($_POST[message] = ""){
$message_err = "<font color=red>You forgot to give us a message.</font><br />";
$send = "no";
}
/*This next if statement says it's ok to send*/
if ($send != "no") {
$msg = "Email sent from www site\n";
$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's Email: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
$to = "brad@glacierridge.ca";
$subject = "All in one Web site feedback";
$mailheaders = "From: My Web Site <http://www.glacierridge.ca>\n";
$mailheaders .= "Reply to: $_POST[sender_email]\n";
mail($to, $subject, $msg, $mailheaders);
echo "<p>Mail has been sent!</p>";
}
/*the next else if sends the error messages if the text fields or message box is empty*/
else if ($send =="no"){
echo "$name_err";
echo "$email_err";
echo "$message_err";
/*and then it print's the form again*/
echo "$form_block";
}
}
?>
</body>
</html>
Thanks for your help!
New to php and i'm working through exercises in a text book. I have finished the script, put it on my server, when I hit the Submit button I receive this message "Error 404: NOT FOUND!Your browser cannot find the document corresponding to the URL you typed in. ". After hitting the submit button, In my address bar it looks like it's trying to find a file named POST. After going through the code I can't figure out why it's looking for POST. (I only have this one file (allinone_form.php) on my server in a folder (phptext), I'm assuming I only need the one file considering it's an "all in one" form. Anyways, here is the code, could someone please help clarify what I have done wrong? It would really help to understand before I move on...
<? //Below I am putting the ENTIRE form into a variable called $form_block
/*When you use $_SERVER[PHP_SELF] as a form action, you're saying, "When
the submit button is clicked, reload this script and do something."
$_SERVER[php_self] has a value of the script's current name (allinone_form.php)
*/
$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<p><strong>Your Name:</strong><br />
<INPUT type=\"text\" NAME= \"sender_name\" SIZE=30></p>
<p><strong>Your Email Address:</strong><br />
<INPUT type=\"text\" NAME=\"sender_email\" SIZE=30></p>
<p><strong>Message:</strong><br />
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></p>
</form>";
/*the 3 if statements below just make sure there's something in the appropriate fields*/
if ($_POST[op] != "ds"){
//this then shows the form...
echo "$form_block";
}else if ($_POST[op] == "ds") {
if ($_POST[sender_name] ==""){
$name_err = "<font color=red>You forgot to enter your name!</font><br />";
$send = "no";
}
if($_POST[sender_email] = "" ){
$email_err = "<font color=red>We need your email address dude.</font><br />";
$send = "no";
}
if($_POST[message] = ""){
$message_err = "<font color=red>You forgot to give us a message.</font><br />";
$send = "no";
}
/*This next if statement says it's ok to send*/
if ($send != "no") {
$msg = "Email sent from www site\n";
$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's Email: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
$to = "brad@glacierridge.ca";
$subject = "All in one Web site feedback";
$mailheaders = "From: My Web Site <http://www.glacierridge.ca>\n";
$mailheaders .= "Reply to: $_POST[sender_email]\n";
mail($to, $subject, $msg, $mailheaders);
echo "<p>Mail has been sent!</p>";
}
/*the next else if sends the error messages if the text fields or message box is empty*/
else if ($send =="no"){
echo "$name_err";
echo "$email_err";
echo "$message_err";
/*and then it print's the form again*/
echo "$form_block";
}
}
?>
</body>
</html>
Thanks for your help!