<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Send Us An E-Mail!</title> </head> <body> <form name="send_email" id="send_email" method="post" action="email.php"> <div><strong>Full Name:</strong> <input type="text" name="full_name" id="full_name" maxlength="100" /></div> <div><strong>E-Mail Address:</strong> <input type="text" name="email_address" id="email_address" maxlength="100" /></div> <div><strong>Message:</strong> <textarea name="message" id="message"></textarea></div> <div><input type="submit" name="submit" id="submit" value="Submit E-Mail" /> <input type="reset" name="reset" id="reset" value="Reset Form" /></div> </form> </body> </html>
<?php if(!isset($_POST['submit'])) { include "email.html"; exit(); } else { $errors = array(); $full_name = trim($_POST['full_name']); $email_address = trim($_POST['email_address']); $message = trim($_POST['message']); $full_name = htmlentities(strip_tags(preg_replace("/(\!|\@|\#|\$|\%|\^|\&|\*|\(|\))/", "", $full_name))); if(!preg_match("/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/", $email_address)) { $errors['email_address'] = "Invalid E-Mail Address!"; } if(count($errors) != 0) { echo $errors; exit(); } else { // ... } } ?>