Mail vérification php

Fermé
Tekuni-DD Messages postés 7 Date d'inscription lundi 4 avril 2011 Statut Membre Dernière intervention 6 avril 2011 - Modifié par Tekuni-DD le 5/04/2011 à 08:37
Tekuni-DD Messages postés 7 Date d'inscription lundi 4 avril 2011 Statut Membre Dernière intervention 6 avril 2011 - 5 avril 2011 à 16:40
Bonjour,


Je doit faire un formulaire avec nom, prenom, email, objet, message, liste de choix pour le destinataire (il peux en avoir plusieurs) et un captcha.

Ce que j'arrive bien est de faire le formulaire et le captcha bien vérifier qu'il ne manque pas de champs. Et ce que j'arrive pas à faire c'est de l'envoyer si la vérification est ok.


Formulaire.php

<?php session_start(); ?>   

<?php   
// N'afficher que les erreurs, pas les avertissements...   
ini_set("error_reporting", "E_ALL & ~E_NOTICE");   

$email_dest = implode(', ', $_POST[destinataire]);   

if ($_POST['envoi']) {   


// E-mail headers:   
$headers ="MIME-Version: 1.0 \n";   
$headers .="From: monsite<mail>\n";   


$headers .="Content-Type: text/html; charset=iso-8859-1 \n";   

$subject = $_POST['champ1'];   
for ($a=4; $a<= $_POST['nbre_champs_texte']; $a++) {   
$partie_champs_texte .= "<font face='Verdana' size='2' color='#003366'>" . $_POST['titre_champ'.$a] . " = " . $_POST['champ'.$a] . "</font><br>";   
}   

if ($_POST['nbre_zone_email'] != 0) {   
$partie_zone_email = "<font face='Verdana' size='2' color='#003366'>" . $_POST['titre_email'] . " = " . $_POST['zone_email'] . "</font><br>";   
}   

if ($_POST['nbre_zones_texte'] != 0) {   
$partie_zone_texte = "<font face='Verdana' size='2' color='#003366'>" . $_POST['titre_zone'] . " = " . $_POST['zone_texte'] . "</font><br>";   
$partie_zone_texte = stripslashes($partie_zone_texte);   
}   

$fin = "</body></html>";   

$sortie = $partie_entete . $partie_champs_texte . $partie_zone_email . $partie_zone_texte . $fin;   

// Send the e-mail   
if (@!mail($email_dest,$subject,$sortie,$headers)) {   
echo("Envoi du formulaire impossible");   
} else { // Closing if !mail...   

// Renvoi à la page de remerciement   
header("Location:1.php");   
exit();   

} // Fin du else   
} // Closing if edit   
?>   
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   

<html xmlns="http://www.w3.org/1999/xhtml">   
 <head>   
 </head>   
 <body>           
        <table class="BORDURE_FORMULAIRE" width="1024px" border="0" cellpadding="0" cellspacing="0" bgcolor="#74777c">   
         <tr>   
             <td>   
                 <form action="verification.php" method="post">   
                    <table width="1000px" border="0" cellpadding="0" cellspacing="0">   
                         <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                         <tr >   
                             <td> </td>   
                             <td><label >Nom</label> :</td>   
                                <td><input type="text" name="nom" id="nom"/><br/></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                             <td><label >Prénom</label> :</td>   
                                <td><input type="text" name="prenom" id="prenom"/><br/></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                             <td><label >Email</label> :</td>   
                                <td><input type="text" name="email" id="email"/><br/></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                             <td><label>Objet</label> :  </td>   
                                <td><input type="text" name="objet" id="objet"/><br/></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
<tr>   
                             <td> </td>   
                                <td><label for="contenu">Message</label> :<br /></td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                                <td> </td>   
                                <td><textarea name="contenu" id="contenu" rows="10" cols="100"></textarea><br/></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                             <td><label for="destinataire">Destinataire</label></td>   
                                <td>   
                                      <ul>   
                                          <li><input type="checkbox" name="destinataire[]" value="adresse@hotmail.fr"> Hotmail</li>   
                                          <li><input type="checkbox" name="destinataire[]" value="adresse@yahoo.fr"> Yahoo</li>   
                                          <li><input type="checkbox" name="destinataire[]" value="adresse@etu.iut-tlse3.fr"> Horde</li>   
                                      </ul><br/>   
                                </td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                             <td> </td>   
                                <?php require('captcha.php'); ?>   
                             <td><label for="captcha">Recopiez le mot : "<?php echo captcha(); ?>"</label></td>   
          <td><input type="text" name="captcha" id="captcha" /><br /></td>   
                            </tr>   
                            <tr>   
                             <td width="46"> </td>   
                                <td width="116"> </td>   
                                <td width="838"> </td>   
                            </tr>   
                            <tr>   
                            <td valign="top"><input name="nbre_champs_texte" type="hidden" id="nbre_champs_texte" value="4">   
               <input name="nbre_zones_texte" type="hidden" value="1">   
         <input name="nbre_zone_email" type="hidden" value="0">   
         <input name="titre_champ1" type="hidden" value="Objet"><input name="titre_zone" type="hidden" value="Message"></td></tr>   
                            <tr>   
                             <td> </td>   
                             <td><input type="submit" value="Envoyer" name="envoi"/></td>   
                                <td><input type="reset" value="Recommencer" /></td>   
                            </tr>   
                        </table>   
                    </form>   
                </td>                
            </tr>   
        </table>   
          
 </body>   
</html>   


Et le vérification.php

<?php session_start(); ?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

<html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 </head>  
 <body>  
  <table width="1024px" height="119" border="0" cellpadding="0" cellspacing="0" bgcolor="#74777c" class="BORDURE_FORMULAIRE">  
         <tr>  
    <td width="104"> </td>  
                <td width="894">  
                  
                <?php  
                if(!empty($_POST['captcha']))  
                {  
                  if($_POST['captcha'] != $_SESSION['captcha'])  
               echo 'Le code doit être identique!<br />';  
                }  
               ?>  

                  
  <?php   
                  $nom = $_POST['nom'];  
                  $prenom = $_POST['prenom'];  
                  $email = $_POST['email'];  
                  $point = strpos($email,".");  
                  $aroba = strpos($email,"@");  
                  $objet = $_POST['objet'];  
                  $contenu = $_POST['contenu'];  
                  $captcha = $_POST['captcha'];  
                    
                  $erreur = "";  
        
        
                  if (empty($nom) || empty($prenom) || empty($email) || empty($objet) || empty($contenu) || empty($captcha))  
                  {  
                      $message = "Retournez au formulaire.  <br />  
                         Les champs suivants ne doivent pas être vides : <br />";  
                      $erreur="erreur";  
         
                      if (empty($nom))   
                      {  
                        $message .= " Nom";  
                      }  
         
                      if (empty($prenom))  
                      {  
                          $message .= " Prenom";  
                      }  
         
                      if (empty($email))   
                      {  
                          $message .= " Email";  
                      }  
         
                      if (empty($objet))   
                      {  
                          $message .= " Objet";  
                      }  
         
                      if (empty($contenu))   
                      {  
                          $message .= " Message";  
                      }  
                        
       if (empty($captcha))   
                      {  
                          $message .= " Le code";  
                      }   
        
      }  
      elseif (!preg_match("#^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-z]{2,4}$#", $email) || empty($email))  
      {  
        $message .= " Votre email est invalide";  
                  }        
        
                  else   
                  {  
                      $message="Mail envoyer!";  
                  }  
                      echo $message."<br />";  
         
         
                  if ($erreur) ;  
                
              ?>  
            </tr>  
        </table>  
 </body>  
</html>
A voir également:

2 réponses

wyllyjon Messages postés 30 Date d'inscription mardi 5 avril 2011 Statut Membre Dernière intervention 8 avril 2011 6
5 avril 2011 à 16:24
Salut !

Le problème que tu as là, c'est que tu ne fais aucun traitement si il n'y a pas d'erreur. Voilà les étapes de ton code :

- Tu rempli ton formulaire et tu le submit
- Ton formulaire est bien envoyé, à la page verification.php.
- Ta page verification.php fait la vérification des champs et affiche une erreur si il y en a.

Ce qui te manque :
- A la fin de ta page verification.php, si il n'y a pas d'erreur, il faut que tu fasses le traitement de tes données.
0
Tekuni-DD Messages postés 7 Date d'inscription lundi 4 avril 2011 Statut Membre Dernière intervention 6 avril 2011
5 avril 2011 à 16:40
C'est bon j'ai réussi a faire ce que je voulais faire!!

Merci de t'as réponse.
0