hi.
i also have a working php script which almost does what you are asking... mine is just to send a regular e-mail, but you can extrapolate this script into someting with a bigger/different form.
the code: (a little bit trimmed down)
// email.php
<?php
if(!isset($POST["msgtext"]))
{
$state=0;
// we are starting the form script - i.e. no data yet
// $state variable explanation below
}
else
{
// we have data, but is it ok?
if(($POST["return_address"]) && ($POST["from"]) && ($POST["subject"])) {
// all variables are filled, but are they ok?
// return address must have both a "@" and a "." (at least)
if(!strchr($POST["return_address"],'@') || !strchr($POST["return_address"],'.')) {
$state=3;
// return address not valid
}
else
{
$state=1;
// we have verified the information and it is appearently ok
$top_title="feedback ok";
}
}
else
{
$state=2;
$top_title="feedback error";
}
}
// disallow caching
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
// The $state variable tells us how to handle the script:
//
// $state=0 - the script is beginning. no data yet.
// The script will show the form for people to fill in and then
// click the submit button.
//
// $state=1 - the script was filled and submitted. The data is
// available to work with and has been verified (above) and
// found valid
// The script will send the e-mail
//
// $state=2 - important fields were not filled.
// the script will stop with an error message
//
// $state=3 - the script was filled and submitted. the data is
// available to work with but was verified and found invalid.
// The script will show an error message telling the user that
// the form was miss-filled.
// the script will stop with an error message
//
// Let's check the $state variable to check out what to do
switch ($state) {
case 0:
?>
// - ** - trimmed html form code - ** -
// i.e. you should write your form here
// important fields are:
<form method=post action="email.php">
// identification - nickname
<input type="text" name="from">
// return address
<input type="text" name="return_address">
// message subject
<input type="text" name="subject">
// message
<textarea rows="11" cols="60" name="msgtext"></textarea>
// submit button
<input type="submit">
</form>
<?php
break;
case 1:
// send mail
if(mail(/ DESTINATION E-MAIL HERE /somewhere@on.mars,"WEB: $POST[subject]","$POST[from] wrote: \n$_POST[msgtext]$
// show html telling that e-mail sending was ok
}
else
{
// show html telling that e-mail was not sent. there was some
// problem: i.e. mail returned a false value
}
break;
case 2:
// warn user that he/she should fill the form again
// give form link
break;
case 3:
// warn user that return address is not valid and that
// he/she should fill the form again
// give form link
break;
default:
break;
}
?>
That's it.
Note however that one can improve this script by including the html form code in a function and if there is an error, you could show the form again, just after the error message, and if you really want to waste time, you can fill the form with the previous valid values, so that the user doesn't have to fill them all again.
If you want to see it working, check out at http://arrakis.dhis.org/email.php
hope it helps...
good luck!