User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,612 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,618 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: 3744 | Replies: 13
Join Date: Mar 2004
Posts: 4
Reputation: wise1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
wise1 wise1 is offline Offline
Newbie Poster

Learning PHP but problem with script

  #1  
Mar 13th, 2004
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]
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC