E-mail
<?php
// If the submit button has been pressed
if(isset($_POST['submit']))
{
// Check for an e-mail address
if(empty($_POST['email']))
{
$error['email'] = 'You forgot to type in an e-mail address';
}
// Check for a subject
if(empty($_POST['subject']))
{
$error['subject'] = 'You forgot to type in a subject';
}
// Check for a message
if(empty($_POST['message']))
{
$error['message'] = 'You forgot to type in a message';
}
// If there are no errors, send the email
// If there are errors, display them to the user
if(sizeof($error) == 0)
{
// Let's send the message (to, subject, message, from)
// Change address@host.com to your own e-mail address
mail('address@host.com', stripslashes($_POST['subject']), stripslashes($_POST['message']), "From: {$_POST['email']}");
// Create confirmation message
echo 'Your e-mail has been sent!';
} else {
// Display error messages
foreach($error as $value)
{
echo "<span style=\"color: #990000\">{$value}</span><br />";
}
}
}
?>
<!-- E-mail Form -->
<form method="post" action="email.php">
<label for="email">Your e-mail address:</label><br />
<input name="email" type="text" value="<?php echo $_POST['email']; ?>" /><br /><br />
<label for="subject">Subject:</label><br />
<input name="subject" type="text" value="<?php echo stripslashes($_POST['subject']); ?>" /><br /><br />
<label for="message">Message:</label><br />
<textarea name="message" rows="8" cols="30"><?php echo stripslashes($_POST['message']); ?></textarea><br /><br />
<input name="submit" type="submit" value="Send Message" />
</form>