par
Mc_Bounce » 10 oct. 2006, 14:05
Bonjour,
Je débute totalement dans le php et j'ai récuperé ce bout d code pour un formulaire. Celui-ci fonctionne bien, mon seul souci est de savoir comment faire pour vérifier si le mail est valide xxxx + @ + xxxx . xxxx
Si vous pouviez m'aider merci beaucoup
Le code :
<?php
if ($mode == "submit") {
if ($enable_html != "on") {
/*
Les utilisateurs peuvent ou non envoyer le mail au format HTML
*/
$mail_body = "Nom - $mail_nom <br> Prenom - $mail_prenom<br>
Département - $mail_dpt<br>
Texte - $mail_body";
}
$mail_to = "
[email protected]";
$mail_subject = "Mail depuis le site";
// On construit les entetes
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$headers .= "from:$mail_from\r\nCc:$mail_cc\r\nBcc:$mail_bcc";
/*
La fonction mail retourne TRUE si l envoi reussi ou FALSE si il échoue, donc on verifie le resultat
*/
if (@mail ($mail_to, $mail_subject, $mail_body, $headers)) {
include('confirmation.php');
} else {
print ("<h1><font color=\"#880000\">Une erreur est apparue lors de l'envoi. Echec!</font></h1>");
}
// On n'a plus besoin de voir le formulaire
exit;
}
?>
<html>
<head>
<title>Send e-mail</title>
<script language="javascript">
function DoSubmit ()
{
/*
Cette fonction verifie que les champs important on été remplis correctement
Le return "" annule l'envoi du formulaire en cas d erreur
*/
if (document.form.mail_from.value == "") {
alert ("Vous avez oublié le champ 'De'.");
document.form.mail_from.focus ();
return "";
}
if (document.form.mail_body.value == "") {
alert ("Vous avez oublié le champ 'Message'.");
document.form.mail_body.focus ();
return "";
}
document.form.submit ();
}
</script>
</head>
<body>
<!--
$PHP_SELF permet au formulaire de marcher meme si vous renommez ce fichier
-->
<form action="<?php print ($PHP_SELF); ?>" method="post" name="form">
<table>
<tr>
<td>Nom* :</td>
<td><input type="text" name="mail_nom" size="40"></td>
</tr>
<tr>
<td>Prénom* :</td>
<td><input type="text" name="mail_prenom" size="40"></td>
</tr>
<tr>
<td>E-mail* :</td>
<td><input type="text" name="mail_from" size="40"></td>
</tr>
<tr>
<td>Département* :</td>
<td><select name="mail_dpt" size="1">
<option value=''></option>
<option value='01' >01.Ain</option>
<option value='02' >02.Aisne</option>
<option value='94' >94.Val-de-Marne</option>
<option value='95' >95.Val-d’Oise</option>
<option value='97' >97.DOM</option>
</SELECT>
</td>
</tr>
<tr>
<td valign="top">Questions, commentaires...</td>
<td><textarea name="mail_body" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="mode" value="submit"></td>
<td><input type="button" onClick="DoSubmit ()" value="Send e-mail"></td>
</tr>
</table>
</form>
</body>
</html>
Bonjour,
Je débute totalement dans le php et j'ai récuperé ce bout d code pour un formulaire. Celui-ci fonctionne bien, mon seul souci est de savoir comment faire pour vérifier si le mail est valide xxxx + @ + xxxx . xxxx
Si vous pouviez m'aider merci beaucoup
Le code :
<?php
if ($mode == "submit") {
if ($enable_html != "on") {
/*
Les utilisateurs peuvent ou non envoyer le mail au format HTML
*/
$mail_body = "Nom - $mail_nom <br> Prenom - $mail_prenom<br>
Département - $mail_dpt<br>
Texte - $mail_body";
}
$mail_to = "
[email protected]";
$mail_subject = "Mail depuis le site";
// On construit les entetes
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$headers .= "from:$mail_from\r\nCc:$mail_cc\r\nBcc:$mail_bcc";
/*
La fonction mail retourne TRUE si l envoi reussi ou FALSE si il échoue, donc on verifie le resultat
*/
if (@mail ($mail_to, $mail_subject, $mail_body, $headers)) {
include('confirmation.php');
} else {
print ("<h1><font color=\"#880000\">Une erreur est apparue lors de l'envoi. Echec!</font></h1>");
}
// On n'a plus besoin de voir le formulaire
exit;
}
?>
<html>
<head>
<title>Send e-mail</title>
<script language="javascript">
function DoSubmit ()
{
/*
Cette fonction verifie que les champs important on été remplis correctement
Le return "" annule l'envoi du formulaire en cas d erreur
*/
if (document.form.mail_from.value == "") {
alert ("Vous avez oublié le champ 'De'.");
document.form.mail_from.focus ();
return "";
}
if (document.form.mail_body.value == "") {
alert ("Vous avez oublié le champ 'Message'.");
document.form.mail_body.focus ();
return "";
}
document.form.submit ();
}
</script>
</head>
<body>
<!--
$PHP_SELF permet au formulaire de marcher meme si vous renommez ce fichier
-->
<form action="<?php print ($PHP_SELF); ?>" method="post" name="form">
<table>
<tr>
<td>Nom* :</td>
<td><input type="text" name="mail_nom" size="40"></td>
</tr>
<tr>
<td>Prénom* :</td>
<td><input type="text" name="mail_prenom" size="40"></td>
</tr>
<tr>
<td>E-mail* :</td>
<td><input type="text" name="mail_from" size="40"></td>
</tr>
<tr>
<td>Département* :</td>
<td><select name="mail_dpt" size="1">
<option value=''></option>
<option value='01' >01.Ain</option>
<option value='02' >02.Aisne</option>
<option value='94' >94.Val-de-Marne</option>
<option value='95' >95.Val-d’Oise</option>
<option value='97' >97.DOM</option>
</SELECT>
</td>
</tr>
<tr>
<td valign="top">Questions, commentaires...</td>
<td><textarea name="mail_body" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="mode" value="submit"></td>
<td><input type="button" onClick="DoSubmit ()" value="Send e-mail"></td>
</tr>
</table>
</form>
</body>
</html>