Created
January 29, 2010 12:02
-
-
Save evaisse/289676 to your computer and use it in GitHub Desktop.
validate email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$DESTINATAIRE = '[email protected]'; | |
$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