Skip to content

Instantly share code, notes, and snippets.

@evaisse
Created January 29, 2010 12:02
Show Gist options
  • Save evaisse/289676 to your computer and use it in GitHub Desktop.
Save evaisse/289676 to your computer and use it in GitHub Desktop.
validate email
<?php
$DESTINATAIRE = 'mon@adresse.com';
$SUJET = 'Message reçu depuis '.$_SERVER['HTTP_HOST'].' ';
function valid_email($email) {
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
$regex = '/^' . $atom . '+' .
'(\.' . $atom . '+)*' .
'@'.
'(' . $domain . '{1,63}\.)+' .
$domain . '{2,63}$/i';
return preg_match($regex, $email);
}
if( valid_email($_POST['email']) ) {
$_POST = array_map('htmlentities',$_POST);
$HTML = '
<h3>' . $_POST['nom'] . ' ' . $_POST['prenom'] . ' ('. $_POST['email'] . ')</h3>
<p>
'.nl2br($_POST['message']).'
</p>
';
$ok = mail( $DESTINATAIRE,
$SUJET,
$HTML,
"From:".trim($_POST['email'])."\r\n"
."Content-type:text/html;" );
if($ok) header('location: succes.html') and exit();
}
header('location:?erreur') and exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment