PHP Code:
<?php function Head($title) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<?php } function Foot() { ?>
</body>
</html>
<? } function succeed($msg) {
sleep(1);
mail("japhlee@hotmail.com", "New Booking", $msg, "Content-Type: text/plain\r\n\r\n");
Head("Mail sent.");
echo("Your request has been successfully sent.");
Foot();
die();
} function fail($missing) {
Head("Error");
?>
An error has occurred. Please fill in the following fields:
<?=$missing?>
<?php
Foot();
}
if($_POST['name']) {
$missing = "<ul>";
$name = $_POST['name'];
$date = $_POST['date'];
$address = $_POST['address'];
if(!isset($name)) $missing .= "<li>Name</li>";
if(!isset($date)) $missing .= "<li>Date</li>";
if(!isset($address)) $missing .= "<li>Address</li>";
$missing .= "</ul>";
if($missing == "<ul>") {
$msg = "A new booking has arrived from $name at $address on $date.\n\tThanks,\n\t\tYour friendly form mail script.";
succeed($msg);
} else fail($missing);
?>
<?php } } else { Head("Request a Booking"); ?>
<form action="<?=$PHP_SELF?>" method="post">
Name: <input type="text" name="name"/><br/>
Date: <input type="text" name="date"/><br/>
Address: <textarea rows="3" cols="20" name="address"></textarea><br/>
<input type="submit" value="Submit Request"/>
</form>
<?php Foot() } ?>
I haven't tested it, it's too early in the morning, so there are probably bugs. Tweak it as necessary.
Bookmarks