<html>
<head>
<title>Contact</title>
</head>
<body>
<form method="post" action="contact.php">
Name: <br>
<input type="text" name="name"><br><br>
Email: <br>
<input type="text" name="email"><br><br>
Comments: <br>
<textarea name="comments" rows="10" cols="40"></textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
//Let's Go ahead and include our config file containing the contact email
include("config.php");
//Grab all the data
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$comments = trim(stripslashes(strip_tags($_POST['comments'])));
$comments = wordwrap($comments, 70, "<br>\n");
//Check that the email is valid
//Note: only checks the email for the _correct_ format "[email protected]".
//This doesn't necessarily mean it's a real email...heh
$validate = preg_match('/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/', $email);
if(!$validate)
{
echo '<br>'.$email.' is not a valid email.<br>';
exit();
}
else
{
$e = $email;
}
//Check to make sure none of the fields are empty
if(!$name || !$e || !$comments)
{
echo '<br>All fields required, please enter all data.<br>';
exit();
}
else
{
//Commence to sending the form =)
//To send HTML mail, we'll need to set the Content-type header
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From: '.$e."\r\n";
//Ok, now e-mail
$send = mail($contact_email, "Message from: $name", "
<html>
<head>
<meta http-equiv=\"Content-Language\" content=\"en-us\">
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<title>Message from $name</title>
</head>
<body>
<table cellpadding=\"2\" cellspacing=\"0\" width=\"400\" border=\"1\" style=\"border-collapse: collapse\">
<tr>
<td width=\"87\"><b>Name:</b></td>
<td width=\"313\"> $name</td>
</tr>
<tr>
<td width=\"87\"><b>Email:</b></td>
<td width=\"313\"> $e</td>
</tr>
<tr>
<td width=\"87\"><b>Comments:</b></td>
<td width=\"313\"> $comments</td>
</tr>
</table>
</body>
</html>", $headers);
if($send)
{
echo '<br>Thank you '.$name.' for contacting us.<br>';
}
else
{
echo '<br>Sorry, your message could not be sent at this time.<br>Please try again later.<br>';
}
}
}
//And that is all =) Very simple really.
?>
</body>
</html>