<?php # Script 3.4 - index.php
$page_title = 'Beemsterboer Software - Contact';
?>
<head>
<title>Beemsterboer Software</title>
<style>
	body {
		padding: 50px 200px;
		background-color: #CCFFFF;
	}
	.content {
		padding: 10px;
		width: 900px;
		background-color: #99CCFF;
	}
	img {
		float: right;
		padding: 10px;
	}
	p {
		width: 700px;
	}

</style>
</head>
<body>
<div class="content">
<h1>Contact form</h1>
<?php # Script 10.1 - email.php

// Check for form submission:
if (isset($_POST['submitted'])) {

	// Minimal form validation:
	if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) {
	
		// Create the body:
		$body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}";
		
		// Make it no longer than 70 characters long:
		$body = wordwrap($body, 70);
	
		// Send the email:
		mail('hans@beemsoft.nl', 'Bericht voor Beemsterboer Software', $body, "From: {$_POST['email']}");
		
		// Print a message:
		echo '<p><em>Thanks for the message. I will get back to you as soon as possible.</em></p>';
		
	
	} else {
		echo '<p style="font-weight: bold; color: #C00">Please complete the form.</p>';
	}
	
} // End of main isset() IF.
	// Minimal form validation:
	if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) {
		// Clear $_POST (so that the form's not sticky):
		$_POST = array();
}
else {
	
// Create the HTML form:
?>
<p>Please complete the form</p>
<form action="contact.php" method="post">
	<table>
	<tr>
	<td>Name:</td><td><input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></td>
	</tr>
	<tr>
	<td>Email:</td><td><input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></td>
	</tr>
	<tr>
	<td valign="top">Message:</td><td><textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></td>
	</tr>
	<tr>
	<td colspan="2"><input type="submit" name="submit" value="Send!" /></td></tr></table>
	<input type="hidden" name="submitted" value="TRUE" />
</form>
<p>
<?php

} // End of main isset() IF.
?>
<a href="index.html">Back</a>
</p>
</div>
</body>

<?php ?>
