Aide envoie formulaire par mail

Fermé
annemarie1 Messages postés 78 Date d'inscription lundi 28 mai 2007 Statut Membre Dernière intervention 21 août 2009 - 18 juin 2008 à 15:55
X-Fan Messages postés 805 Date d'inscription mercredi 4 juin 2008 Statut Membre Dernière intervention 6 janvier 2010 - 18 juin 2008 à 18:37
Bonjour,

j ai un fichiers php ou j aimerai qu le fonction de verif du mail soit plus complete

j ai un fichiers javascript de contarole mais quand je le remplace cela ne fonctionne plus pourrriez vous m aider svp je suis etudiante et debutante
merci

1 er fichiers

<?php
if($HTTP_POST_VARS['MM_Ok']=="1")
{
$destinataire ="ggggggggg@free.fr;
$objet ="Message site Internet";
$message = '
<html>
<head>
<title></title>
</head>
<body>
<table width=\'250\'>
<tr>
<td width="100"><font color="#FF0000">Nom : </font>'.$_POST['Txt_Nom'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Prenom: </font>'.$_POST['Txt_prenom'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Adresse: </font>'.$_POST['Txt_adresse'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Code Postal: </font>'.$_POST['Txt_postal'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Ville: </font>'.$_POST['Txt_ville'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Mail: </font>'.$_POST['Txt_mail'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Telephone: </font>'.$_POST['Txt_tel'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Niveau estimé: </font>'.$_POST['select_niveau'].'</td>
</tr>
<tr>
<td width="100"><font color="#FF0000">Message: </font></td>
</tr>
</table>
</body>
</html>
';

/* Si l’on veut envoyer un mail au format HTML, il faut configurer le type Content-type. */
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";

// On envoi l’email
mail($destinataire, $objet, $message, $headers);

if ( mail($destinataire, $objet, $message, $headers)){
echo "Envoi du mail réussi.";
}else{
echo "Echec de l’envoi du mail.";
}
}
?>
<html>
<head>
<title>contact</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="file:///F|/-= Cours AFCI =-/Php MySQL/style.css" rel="stylesheet" type="text/css">
<link href="file:///F|/-= Cours AFCI =-/Php MySQL/css/highslide.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="file:///F|/-= Cours AFCI =-/Php MySQL/js/highslide.js"></script>
<script type="text/javascript">
hs.graphicsDir = 'images/';
hs.outlineType = null;
window.onload = function() {
hs.preloadImages();
}
</script>
<script type="text/javascript">
<!--
<!--//--><![CDATA[//><!--
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]>

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script language="JavaScript">
function EnvoiMail(){
if (document.getElementById) {
if (document.getElementById('Txt_Nom').value ==''){
alert('Le nom est obligatoire');
}else{
if (document.getElementById('Txt_tel').value ==''){
alert('Le n° téléphone est obligatoire');
}else{
if (document.getElementById('Txt_Message').value ==''){
alert('Le message est obligatoire');
}else{
if (document.getElementById('Txt_mail').value ==''){
alert('Le mail est obligatoire');
}else{

document.form1.submit();
}
}
}
}
}
}

function popup(url, titre, largeur, hauteur, scroll)
{
window.open(url, titre, 'width=' + largeur + ', height=' + hauteur + ', scrollbars=' + scroll);
}
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF">
<table width="289" height="503" cellpadding="0" cellspacing="0">
<tr>
<td width="285">Contact : </td>
</tr>
<tr>
<td height="150" valign="top"> <form enctype="multipart/form-data" name="form1" method="POST" action="">
<table width="300" border="0" cellspacing="0" cellpadding="0" class="normal" >
<tr>
<td width="300"><strong>Nom:</strong></td>
</tr>
<tr>
<td><input name="Txt_Nom" type="text" size="50" maxlength="150" class="Input"></td>
</tr>
<tr>
<td>Prenom:</td>
</tr>
<tr>
<td><p>
<input name="Txt_prenom" type="text" size="50" maxlength="150" class="Input" id="Txt_prenom">
</p>
<p><strong>Adresse:</strong>
<input name="Txt_adresse" type="text" size="50" maxlength="150" class="Input" id="Txt_adresse">
</p>
<p>Code postal
<input name="Txt_postal" type="text" size="50" maxlength="150" class="Input" id="Txt_postal">
</p>
<p>Ville
<input name="Txt_ville" type="text" size="50" maxlength="150" class="Input" id="Txt_ville">
<strong>Niveau estime:</strong>
<select name="select_niveau" id="select_niveau">
<option value="1">forte:Intermediaire</option>
<option value="2">Fortissimo :Avancé</option>
<option value="3">Mezzo Forte :Débutant</option>
<option value="4">Mezzo Piano : Grand Débutant</option>
<option value="5">Piano:Adolescent</option>
<option value="6">Pianissimo:Enfants </option>
</select>
</p> </td>
</tr>
<tr>
<td><strong>Mail:</strong></td>
</tr>
<tr>
<td><input name="Txt_mail" type="text" size="50" maxlength="150" class="Input"></td>
</tr>
<tr>
<td><strong>Téléphone:</strong></td>
</tr>
<tr>
<td><input name="Txt_tel" type="text" size="50" maxlength="150" class="Input"></td>
</tr>
<tr>
<td><strong>Message:</strong></td>
</tr>
<tr>
<td><textarea name="Txt_Message" cols="47" rows="24" class="Input" ></textarea></td>
</tr>
<tr>
<td align="right" class="link" height="20"><input type="hidden" id="MM_Modif" name="MM_Ok" value="1" class="Input"> <a href="#" onClick="javascript:EnvoiMail()" class="link">Envoyer >></a></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>


2eme fichiers (javascript)
<script>
function validMail(nomChamp){

//récupérer saisie dans le champ txt_mail
valeur=document.getElementById(nomChamp).value;

//longueur du champ de saisie
nbCaracteres=valeur.length;

//les if pour détecter les erreurs par ordre de priorités.
// vérifie si nb de caractères< 6 =>renvoi valeur faux. sinon continue vérif.
if (nbCaracteres<6){
return false;
}else{
//vérifie que ds valeur si chp de txt avec espace, on a un renvoi de valeur faux
if (valeur.indexOf(" ")!=-1){
// si on est ici c'est qu'il a trouvé un espace
return false;
}else{
//vérifie à partir de la saisie la présence d'un @ - si valeur=-1 signifie que pas d'@
//création variable pour ensuite l'utiliser comme pt de référence pour trouver le 2èm @
positionAro1 =valeur.indexOf("@");
if (positionAro1 ==-1){
return false;
}else{
positionAro1 = positionAro1 +1;
positionAro2 = valeur.indexOf("@",positionAro1);
if (positionAro2 != -1){
//il a trouvé un deuxième @ au moins
return false;
}else{
// si ici c'est qu'il n'a trouvé qu'un seul @ => positionAro2 == -1
positionPoint = valeur.indexOf(".",positionAro1);
if (positionPoint == -1){
return false;
}else{
//si ici c'est qu'on a pas d'erreur c'est lessieur
return true;
} // fin if positionPoint == -1
}// fin if positionAro2 != -1
}// fin if positionAro1 ==-1
} // fin if valeur.indexOf(" ")!=-1
} // fin if nbCaracteres<6
}// fin function validMail(nomChamp)
////fin de function verif
</script>
A voir également:

1 réponse

X-Fan Messages postés 805 Date d'inscription mercredi 4 juin 2008 Statut Membre Dernière intervention 6 janvier 2010 19
18 juin 2008 à 18:37
Bah de façon simple en php tu peux faire un truc comme ça:

// the email to send to
$myemail = 'ted@platypus.org.uk';

if(!preg_match('/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/',$_POST['email']))
die('Invalid email proved, the email must be in valid email format (such as name@domain.tld).');
0