here is a VERY simplified example, tweak as needed:
function form ()
{
echo '
<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">
name: <input type="text" name="name" value="'; if (isset ($_POST['name'])) {echo $_POST['name'];} echo '"><br>
email: <input type="text" name="email" value="'; if (isset ($_POST['email'])) {echo $_POST['email'];} echo '"><br>
<input type="submit" name="submit" value="submit">
</form>
';
}
if (!isset ($_POST['submit']))
{
form ();
}
if (isset ($_POST['submit']) && $_POST['submit'] == 'submit')
{
foreach ($_POST as $key => $value)
{
$value = strip_tags ($value);
$value = stripslashes ($value);
$value = trim ($value);
$_POST[$key] = $value;
}
echo '
<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">
<input type="hidden" name="name" value="' . $_POST['name'] . '">
<input type="hidden" name="email" value="' . $_POST['email'] . '">
You enter:<br><br><b>' . $_POST['name'] . '<br>' . $_POST['email'] . '</b><br><br>If this is correct hit <input type="submit" name="submit" value="send">. Otherwise update form below and hit submit.
</form>
';
form ();
}
if (isset ($_POST['submit']) && $_POST['submit'] == 'send')
{
$from = 'from: "' . $_POST['name'] . '" <' . $_POST['email'] . '>';
$to = 'CapEsiouS <CapEsiouS@CapEsiouS.com>';
$subject = 'this is the subject';
$message = 'this is the message';
$mail_sent = @mail ($to, $subject, $message, $from);
if ($mail_sent) {echo 'mail successfully sent';} else {echo 'mail failed';}
}