•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,922 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,354 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3839 | Replies: 13
![]() |
| |
•
•
Join Date: Mar 2004
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
This is a simple script I copied from a book to create a form, then mail it to an address.
I cant get it too wok and wonder if its the script or my server. I even copied the source form the publishers website and it still wont work.
Basically all it should do is show a form, error check it and then send it.
Can anyone tell me what maybe wrong with it or if its maybe just my server setup.
[PHP]<HTML>
<HEAD>
<TITLE>All-In-One Feedback Form</TITLE>
</HEAD>
<BODY>
<?
$form_block ="
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<P><strong>Your Name:</strong><br>
<INPUT type=\"text\" NAME=\"sender_name\" VALUE=\"$_POST[sender_name]\" SIZE=30></P>
<P><strong>Your E-Mail Address:</strong><br>
<INPUT type=\"text\" NAME=\"sender_email\" VALUE=\"$_POST[sender_email]\" SIZE=30></P>
<P><strong>Message:</strong><br>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual>$_POST[message]</TEXTAREA></P>
<INPUT type=\"hidden\" name=\"op\" value=\"ds \">
<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></p>
</FORM>";
if ($_POST[op] != "ds") {
//they need to see the form
echo "$form_block";
} else if ($_POST[op] == "ds") {
//check value of $_POST[sender_name]
if ($_POST[sender_name] == "") {
$name_err ="<font color=red>Please enter your name!</font><br>";
$send ="no";
}
//check value of $_POST[sender_email]
if ($_POST[sender_email] == "") {
$email_err ="<font color=red>Please enter your e-mail address!</font><br>";
$send ="no";
}
//check value of $_POST[message]
if ($_POST[message] == "") {
$message_err ="<font color=red>Please enter a message!</font><br>";
$send ="no";
}
if ($send != "no"){
//it's ok to send,so build the mail
$msg ="E-MAIL SENT FROM WWW SITE \n";
$msg .="Sender's Name
_POST[sender_name]\n";
$msg .="Sender's E-Mail
_POST[sender_email]\n";
$msg .="Message
_POST[message]\n \n";
$to ="you@yourdomain.com";
$subject ="All-in-One Web Site Feedback";
$mailheaders ="From:My Web Site <>\n";
$mailheaders .="Reply-To
_POST[sender_email]\n\n";
//send the mail
mail($to,$subject,$msg,$mailheaders);
//display confirmation to user
echo "<P>Mail has been sent!</p>";
} else if ($send =="no"){
//print error messages
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?> [/PHP]
I cant get it too wok and wonder if its the script or my server. I even copied the source form the publishers website and it still wont work.
Basically all it should do is show a form, error check it and then send it.
Can anyone tell me what maybe wrong with it or if its maybe just my server setup.
[PHP]<HTML>
<HEAD>
<TITLE>All-In-One Feedback Form</TITLE>
</HEAD>
<BODY>
<?
$form_block ="
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<P><strong>Your Name:</strong><br>
<INPUT type=\"text\" NAME=\"sender_name\" VALUE=\"$_POST[sender_name]\" SIZE=30></P>
<P><strong>Your E-Mail Address:</strong><br>
<INPUT type=\"text\" NAME=\"sender_email\" VALUE=\"$_POST[sender_email]\" SIZE=30></P>
<P><strong>Message:</strong><br>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual>$_POST[message]</TEXTAREA></P>
<INPUT type=\"hidden\" name=\"op\" value=\"ds \">
<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send This Form\"></p>
</FORM>";
if ($_POST[op] != "ds") {
//they need to see the form
echo "$form_block";
} else if ($_POST[op] == "ds") {
//check value of $_POST[sender_name]
if ($_POST[sender_name] == "") {
$name_err ="<font color=red>Please enter your name!</font><br>";
$send ="no";
}
//check value of $_POST[sender_email]
if ($_POST[sender_email] == "") {
$email_err ="<font color=red>Please enter your e-mail address!</font><br>";
$send ="no";
}
//check value of $_POST[message]
if ($_POST[message] == "") {
$message_err ="<font color=red>Please enter a message!</font><br>";
$send ="no";
}
if ($send != "no"){
//it's ok to send,so build the mail
$msg ="E-MAIL SENT FROM WWW SITE \n";
$msg .="Sender's Name
_POST[sender_name]\n";$msg .="Sender's E-Mail
_POST[sender_email]\n";$msg .="Message
_POST[message]\n \n";$to ="you@yourdomain.com";
$subject ="All-in-One Web Site Feedback";
$mailheaders ="From:My Web Site <>\n";
$mailheaders .="Reply-To
_POST[sender_email]\n\n";//send the mail
mail($to,$subject,$msg,$mailheaders);
//display confirmation to user
echo "<P>Mail has been sent!</p>";
} else if ($send =="no"){
//print error messages
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?> [/PHP]
•
•
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation:
Rep Power: 7
Solved Threads: 6
ergh. That is pehaps the worst script I've seen in a long time.
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
Did you set up a mail server?
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation:
Rep Power: 7
Solved Threads: 6
Here's the problem:
[php]
$to ="you@yourdomain.com";
[/php]
Change to (and change the you@yourdomain.com appropriately)
[php]
$to ='you@yourdomain.com';
[/php]
and I will add that the script is unecessarily resource intensive; hard to follow due to improper indentation and using " where ' would have been preferable; doesn't teach how variables and strings ARE different (you don't need to and shouldn't put a variable inside a string on it own); uses outdated and depreciated HTML standards (without even a <!DOCTYPE>); and doesn't use TRUE and FALSE definitions ( $send = "no"!? What kind of rubbish is that? )
[php]
$to ="you@yourdomain.com";
[/php]
Change to (and change the you@yourdomain.com appropriately)
[php]
$to ='you@yourdomain.com';
[/php]
and I will add that the script is unecessarily resource intensive; hard to follow due to improper indentation and using " where ' would have been preferable; doesn't teach how variables and strings ARE different (you don't need to and shouldn't put a variable inside a string on it own); uses outdated and depreciated HTML standards (without even a <!DOCTYPE>); and doesn't use TRUE and FALSE definitions ( $send = "no"!? What kind of rubbish is that? )
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
•
•
•
•
Originally Posted by Roberdin
and doesn't use TRUE and FALSE definitions ( $send = "no"!? What kind of rubbish is that? )
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation:
Rep Power: 7
Solved Threads: 6
or prefeably, true or false. Then, it's just a matter of
if( $send )
{
// send
}
if( $send )
{
// send
}
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
•
•
•
•
Originally Posted by Roberdin
or prefeably, true or false. Then, it's just a matter of
if( $send )
{
// send
}
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Mar 2004
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Aplogies, I should have stated that this is the code straight form the book, or the cd at least.
I typed it all myself to learn the concept of the script using my own domain, etc.....
The way the book taught me was this, so you understand.
First I created a form in HTML and saved that file as entermail.html, the form action was to call a script called sendemail.php which had the script to send the email after getting the values from the entermail.html
So that was two scripts to send the e-mail.
It then goes on to show you (the script above) how to create just 1 file to setup the form and send the mail. The above script is not working even if I put in my domain details.
Ignore my ignorence here but this is what I thought strange.
There is a hidden field in the scripts $form_block area called "op" (operation)
That field has a value of "ds" (do something)
So basically what the book is saying is that when you run the script the first time it shows the form as the "op" field has a value of "ds", you can then enter your details in the form.
Following me so far?
Okay so the form action in the script has a value of
$_SERVER[PHP_SELF]
this tell me that your going to run the script again upon the user pressing the submit butotn on the form.
So what should happen now is that the value of "op" should now be not equal (!=) to ds, this would then mean that the script has been run to collect the data and you now want to send the mail and output the "mail sent" message.
So if the value of "op" is not "ds" then the form will not be displayed.
But there is at no point in the script an option to change the value of "op" so how can it tell if something has happened to cause it not to display?
As I say I am new to this but thats my thoughts, anyone care to at least shoot me down and say I am talking rubbish.
:cheesy:
I typed it all myself to learn the concept of the script using my own domain, etc.....
The way the book taught me was this, so you understand.
First I created a form in HTML and saved that file as entermail.html, the form action was to call a script called sendemail.php which had the script to send the email after getting the values from the entermail.html
So that was two scripts to send the e-mail.
It then goes on to show you (the script above) how to create just 1 file to setup the form and send the mail. The above script is not working even if I put in my domain details.
Ignore my ignorence here but this is what I thought strange.
There is a hidden field in the scripts $form_block area called "op" (operation)
That field has a value of "ds" (do something)
So basically what the book is saying is that when you run the script the first time it shows the form as the "op" field has a value of "ds", you can then enter your details in the form.
Following me so far?
Okay so the form action in the script has a value of
$_SERVER[PHP_SELF]
this tell me that your going to run the script again upon the user pressing the submit butotn on the form.
So what should happen now is that the value of "op" should now be not equal (!=) to ds, this would then mean that the script has been run to collect the data and you now want to send the mail and output the "mail sent" message.
So if the value of "op" is not "ds" then the form will not be displayed.
But there is at no point in the script an option to change the value of "op" so how can it tell if something has happened to cause it not to display?
As I say I am new to this but thats my thoughts, anyone care to at least shoot me down and say I am talking rubbish.
:cheesy:
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- learning php (PHP)
- Database class use (PHP)
- Learning PHP (PHP)
- php mysql problem (PHP)
- Converting from VB6 - php XOR Problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP chat help
- Next Thread: PHP file calling html control names




Hybrid Mode