here's a form you can put in your document root directory. name it 'emailform.html':
<form action="processcafeform.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr>
<tr>
<td>First Name</td>
<td align="center"><input type="text" name="fname"
size="30" maxlength="30"/></td>
</tr>
<tr>
<td>Last Name</td>
<td align="center"><input type="text" name="lname"
size="30" maxlength="30" /></td>
</tr>
<tr>
<td>Email Address</td>
<td align="center"><input type="text" name="email" size="30" maxlength="30" /></td>
</tr>
<tr>
<td>PC Number</td>
<td align="center"><input type="text" name="pcnum" size="5" maxlength="5" /></td>
</tr>
<tr>
<td>Comments, Requests, Feedback</td>
<td align="center"><textarea name="comments" rows="10" columns="40"/></textarea></td>
</tr>
<tr>
<td>How did you find out about my Internet Cafe? </td>
<td><select name="find">
<option value = "a">I'm a regular customer </option>
<option value = "b">TV advertising </option>
<option value = "c">Phone directory </option>
<option value = "d">Word of mouth </option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
the form above references a file called 'processcafeform.php'. put it in the same directory. here's the code:
<html>
<head>
<title>Your Internet Cafe - Form Results</title>
</head>
<body>
<h1>Thank you for the feedback!</h1>
<h2>We appreciate your business.</h2>
<?php
// create short variable names for form data
$firstname = $POST['fname'];
$lastname = $POST['lname'];
$email = $POST['email'];
$pcnum = $POST['pcnum'];
$comments = $POST['comments'];
$find = $POST['find'];
$date = date('H:i, jS F');
// set shortname server var
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
if( $firstname =="" && $lastname=="" && $email=="" && $pcnum=="" && $comments=="")
{
echo 'You did not enter information on the previous page!<br />';
}
else
{
echo '<p><u>Here is the information you provided</u></p>';
echo '<p>Your name is: <i> '.$firstname.' '.$lastname.'</i></p>';
echo '<p>Your email address is:<i> '.$email.'</i></p>';
echo '<p>You are currently using computer: <i> #'.$pcnum.'</i></p>';
echo '<p>You provided the following feedback: </p>';
echo '<p><i>'.$comments.'</i></p>';
}
// create data var for text file
$outputtext = $firstname."\t".$lastname."\t\t".$email."\t\t"
.$pcnum."\t\t".$comments."\t".$find."\n";
// open file for appending form data
//BE SURE YOU HAVE A DIRECTORY NAMED orders THAT IS LOCATED OUTSIDE OF, AND ON
//THE SAME LEVEL AS THE DOCUMENT ROOT
@ $fp = fopen("$DOCUMENT_ROOT/../orders/cafe.txt", 'ab');
if (!$fp)
{
echo '<p><strong> Your comments could not be saved to the server at this time.</strong></p>';
echo '<p><strong> Please try again later.</strong></p></body></html>';
exit;
}
fwrite($fp, $date.'--'.$outputtext, strlen($date.'--'.$outputtext));
fclose($fp);
echo '<p>Comments submitted on ';
echo $date;
echo '</p>';
echo '<p>Information saved to server.</p>';
?>
</body>
</html>
last, but not least, here's a file called 'cafeview.php' this file will allow you to look at the form output using a web browser. place this file in the same directory.
<?php
//create short variable name
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Your Internet Cafe - Comment and Feedback Viewer</title>
</head>
<body>
<h1>Internet Cafe Customer Information and Feedback</h1>
<?php
@ $fp = fopen("$DOCUMENT_ROOT/../orders/cafe.txt", 'r');
if (!$fp)
{
echo '<p><strong>Could not open comment file.'
.'Please try again later.</strong></p></body></html>';
exit;
}
while (!feof($fp))
{
$feedback= fgets($fp, 999);
echo $feedback.'<br>';
}
fclose($fp);
?>
</body>
</html>
try it out