<form method="POST" name="contactform" action="contact-form-handler.php">
<table width="520px" class="cflite">
<tr>
<td width="167">
<label for='name'>Nome e Cognome<span class="required_star"> * </span></label>


<input type="text" name="name" style="width:250px"></td>
<td width="272"><label for='email'> E-mail<span class="required_star"> * </span></label>


<input type="text" name="email" style="width:250px"></td>
</tr>
<tr>
<td width="100%" colspan="3" valign="top" class="cflite_td"><label for='oggetto'> Oggetto<span class="required_star"> * </span></label>


<input type="text" name="oggetto" style="width:100%"></td>
</tr>
<tr>
<td colspan="3" valign="top" class="cflite_td"> <label for='message'>Messaggio<span class="required_star"> * </span></label>


<textarea style="width:100% ;height:200px" name="message"></textarea></td>
</tr>
<tr>
<td colspan="3" style="text-align:center" class="cflite_td"><div align="left">
<input type="submit" value=" Invia " style="width: 100%">
</div></td>
</tr>
</table>
</form>

<script language="JavaScript">

var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("name","req","Inserire il nome correttamente");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("oggetto","req","Please provide your subject");
frmvalidator.addValidation("email","email","Please enter a valid email address");

Codice PHP:

<?php
$errors = '';
$myemail = 'xxxx@xxxxxxxx.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['oggetto']) ||
empty($_POST['message']))
{
$errors .= "\n Error: Completare tutti i campi richiesti.";
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$oggetto = $_POST['oggetto'];
$message = $_POST['message'];

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Errore: Indirizzo e-mail errato!";
}

if( empty($errors))
{
$to = $myemail;
$email_subject = "$oggetto";
$email_body = "Dalla pagina contatti del sito è pervenuta questa mail:".
"\n Name: $name \n Email: $email_address \n Message \n $message";

$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: thanks.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form</title>
</head>

<body>
<?php
echo nl2br($errors);
?>


</body>
</html>
</script>