envoyer piece jointe - Programmation
Ceci répond-il à votre question ? Oui | Non
 

Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : envoyer piece jointe
 
Profil : IDNaute
Plus d'informations

Bonjour  
je voudrai envoyer un fichier joint par un formulaire mais je n'y arrive pas donc j'ai fait des recherche sur internet essayer plusieur truc et j'ai touvais un truc le voici en 2 étapes comme je le veux  
 
Form.html  
 

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.   <title>form</title>
  5. </head>
  6. <body>
  7. <form method="post" action="envoi.php" enctype="multipart/form-data" name="form">
  8. Exp&eacute;diteur: <input name="email" size="25" type="text"><br>
  9. Destinataire: <input name="email_destinaire" size="25" type="text"><br>
  10. Sujet : <input name="subject" size="25" type="text"><br>
  11. Message : <textarea rows="5" name="message" cols="30"></textarea><br>
  12. Fichier joint: <input name="MAX_FILE_SIZE" value="100000" type="hidden">
  13.   <input name="NomFichier" size="16" type="file"><br>
  14. Priorit&eacute;:
  15.   <select name="priorite" size="1">
  16.   <option value="1">Urgent</option>
  17.   <option value="2">Haute</option>
  18.   <option value="3">Moyenne</option>
  19.   <option value="4">Basse</option>
  20.   <option value="5">Tr&egrave;s basse</option>
  21.   </select>
  22.   <br>
  23.   <input value="Envoyer ce message" type="submit">
  24. </form>
  25. </body>
  26. </html>


 
 
et envoi.php  

Code :
  1. <?php
  2. /*----------------------- Installation -------------------------
  3. Utilité >> Envoi un fichier fichier joint
  4. Nom du fichier >> envoi.php
  5. Créé le  >> 17/09/01
  6. 1°) Donner l'action du formulaire vers ce fichier
  7. 2°) Créer un repertoire (dossier) nommé "transit"
  8.         à la racine de votre site,
  9.         et mettez le en CHMOD 777
  10.         (voir $NomFichier_name)
  11. >> pour toutes informations >> http://www.akoter.com/forum/
  12. --------------------------------------------------------------*/
  13. $destinataire = $email_destinaire ;    // destinatiare du message
  14. $copie_conforme = ""; // copie conforme
  15. $cache_destinataire = ""; // email de surveillance
  16. $objet_page = $subject ; // sujet du message
  17. $redirection = "http://www.monsite.com/mapage.html"; // page de redrection dés le message envoyé
  18. $priorite = $priorite ; // définition de la priorité du message
  19. $reponse=StripSlashes("Votre message est envoyé ;o)" ); // confirmation de l'envoi
  20. // ----------------- début du Code ---------------------- //
  21. class Mail {
  22.         var $sendto= array();
  23.         var $from, $msubject;
  24.         var $acc= array();
  25.         var $abcc= array();
  26.         var $aattach= array();
  27.         var $priorities= array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
  28. function Mail() {
  29.         $this->autoCheck(true);
  30. }
  31. function autoCheck($bool) {
  32.     if($bool)
  33.         $this->checkAddress = true;
  34.     else
  35.         $this->checkAddress = false;
  36. }
  37. function Subject($subject) {
  38.         $this->msubject = strtr($subject, "\r\n" , "  " );
  39. }
  40. function From($from) {
  41.     if( ! is_string($from) ) {
  42.         echo "Class Mail: Erreur, From n'est pas de la bonne forme";
  43.         exit;
  44.     }
  45.     $this->from= $from;
  46. }
  47. function To( $to ) {
  48.     if( is_array( $to ) )
  49.         $this->sendto= $to;
  50.     else
  51.         $this->sendto[] = $to;
  52.     if( $this->checkAddress == true )
  53.         $this->CheckAdresses( $this->sendto );
  54. }
  55. function Cc($cc) {
  56.     if( is_array($cc) )
  57.         $this->acc= $cc;
  58.     else
  59.         $this->acc[]= $cc;
  60.     if( $this->checkAddress == true )
  61.         $this->CheckAdresses( $this->acc );
  62. }
  63. function Bcc($bcc) {
  64.     if( is_array($bcc) ) {
  65.         $this->abcc = $bcc;
  66.     } else {
  67.         $this->abcc[]= $bcc;
  68.     }
  69.     if( $this->checkAddress == true )
  70.         $this->CheckAdresses( $this->abcc );
  71. }
  72. function Body($body) {
  73.     $this->body= $body;
  74. }
  75. function Send() {
  76.     $this->_build_headers();
  77.         if( sizeof( $this->aattach > 0 ) ) {
  78.             $this->_build_attachement();
  79.             $body = $this->fullBody . $this->attachment;
  80.         }
  81.     for( $i=0; $i< sizeof($this->sendto); $i++ ) { // envoie du mail aux destinataires principaux
  82.             $res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
  83.     }
  84. }
  85. function Organization($org) {
  86.     if( trim( $org != "" )  )
  87.         $this->organization= $org;
  88. }
  89. function Priority($priorite) {
  90.     if( ! intval($priorite) )
  91.         return false;
  92.     if( ! isset($this->priorities[$priorite-1]) )
  93.         return false;
  94.     $this->priority= $this->priorities[$priorite-1];
  95.     return true;
  96. }
  97. function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" ) {
  98.     $this->aattach[] = $filename;
  99.     $this->actype[] = $filetype;
  100.     $this->adispo[] = $disposition;
  101. }
  102. function Get() {
  103.     $this->_build_headers();
  104.     if( sizeof( $this->aattach > 0 ) ) {
  105.         $this->_build_attachement();
  106.         $this->body= $this->body . $this->attachment;
  107.     }
  108.     $mail = $this->headers;
  109.     $mail .= "\n$this->body";
  110.     return $mail;
  111. }
  112. function ValidEmail($address) {
  113.     if( ereg( ".*<(.+)>", $address, $regs ) ) {
  114.         $address = $regs[1];
  115.     }   
  116.      if(ereg( "^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|fr|com|gov|mil|org|edu|int)\$",$address) )
  117.          return true;
  118.      else
  119.          return false;
  120. }
  121. function CheckAdresses($aad) {
  122.     for($i=0;$i< sizeof( $aad); $i++ ) {
  123.         if( ! $this->ValidEmail( $aad[$i]) ) {
  124.             echo "Class Mail, method Mail : Adresse Invalide $aad[$i]";
  125.             exit;
  126.         }
  127.     }
  128. }
  129. function _build_headers() {// creation du header mail
  130. $this->headers= "From: $this->from\n";
  131. $this->to= implode( ", ", $this->sendto );
  132.     if( count($this->acc) > 0 ) {
  133.         $this->cc= implode( ", ", $this->acc );
  134.         $this->headers .= "CC: $this->cc\n";
  135.     }
  136.     if( count($this->abcc) > 0 ) {
  137.         $this->bcc= implode( ", ", $this->abcc );
  138.         $this->headers .= "BCC: $this->bcc\n";
  139.     }
  140.     if( $this->organization != ""  )
  141.         $this->headers .= "Organization: $this->organization\n";
  142.     if( $this->priority != "" )
  143.         $this->headers .= "X-Priority: $this->priority\n";
  144. }
  145. function _build_attachement() {
  146. $this->boundary= "------------" . md5( uniqid("myboundary" ) ); // TODO : variable bound
  147. $this->headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$this->boundary\"\n\n";
  148. $this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\nContent-Type: text/plain; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n\n".$this->body."\n";
  149. $sep= chr(13) . chr(10);
  150. $ata= array();
  151. $k=0;
  152.     for( $i=0; $i < sizeof($this->aattach); $i++) {
  153.             $filename = $this->aattach[$i];
  154.             $basename = basename($filename);
  155.             $ctype = $this->actype[$i];
  156.             $disposition = $this->adispo[$i];
  157.             if( ! file_exists( $filename) ) {
  158.                     echo "Class Mail, method attach : file $filename can't be found"; exit;
  159.             }
  160.             $subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n  filename=\"$basename\"\n";
  161.             $ata[$k++] = $subhdr;
  162.             // non encoded line length
  163.             $linesz= filesize($filename)+1;
  164.             $fp= fopen( $filename, 'r' );
  165.             $data= base64_encode(fread( $fp, $linesz));
  166.             fclose($fp);
  167.             $ata[$k++] = chunk_split( $data );
  168.         }
  169.     $this->attachment= implode($sep, $ata);
  170.     }
  171. }
  172. function redir($redirection) { // redirection JavaScript
  173.     echo "<script language=\"javascript\">";
  174.     echo "window.location=('".$redirection."');";
  175.     echo "</script>";
  176. }
  177. $subject=StripSlashes($subject);
  178. $msg=StripSlashes($msg); // construction du message email
  179. $msg ="Message depuis votre site web :\n\n" ;
  180. $msg .= "Subjet : ".$objet_page."\n" ;
  181. $msg .= "Message : ".$message ;
  182. $m= new Mail; // création du email
  183.     $m->From($email);  // création du destinataire
  184.     $m->To($destinataire); // création de l'expéditeur
  185.     $m->Subject($subject); // création du sujet
  186.     $m->Body($msg); // création du message
  187. if ($copie_conforme!='') { //S'il y a une copie conforme du mail
  188.     $m->Cc($copie_conforme);
  189. }
  190.     $m->Priority($priorite) ; 
  191. if ($cache_destinataire!='') { //S'il y a une copie cachée du mail
  192.     $m->Bcc($cache_destinataire);
  193. }
  194.     $m->Priority($priorite) ;
  195. if ($NomFichier_name !='') { // attache le fichier joint
  196.     copy($NomFichier,"./transit/".$NomFichier_name."" );
  197.     $m->Attach( "./transit/".$NomFichier_name."", "application/octet-stream" );
  198. }
  199.     $m->Send(); /* Envoi du mail */
  200. if ($NomFichier_name!='') {
  201.     Unlink("./transit/".$NomFichier_name."" );
  202.     }
  203. echo $reponse ;// Affichage du message d'envoi réussi
  204. if ($redirection !='') {
  205.     redir($redirection); // renvoie sur une page spécifique
  206. }
  207. ?>


 
 
Mais moi je n'est pas appris le code php comme ce la moi mon formulaire est:  
 
recrutement.html  

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  
  5.   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  6.  
  7.   <title>recrutement</title>
  8. </head>
  9. <body>
  10. <form style="width: 448px;" method="post" action="recrutement.php" name="recrutement">
  11.  
  12.   <div style="text-align: right;"></div>
  13.  
  14.   <table style="text-align: left; height: 299px; width: 426px;" border="0" cellpadding="2" cellspacing="2">
  15.     <tbody>
  16.       <tr>
  17.         <td style="text-align: right; width: 111px;">Vous
  18. souhaitez :</td>
  19.         <td style="width: 298px;">
  20.        
  21.         <select name="souhait">
  22.         <option selected="selected">NEGOCIATEUR (TRICE)</option>
  23.         <option>DEMARCHEUR (EUSE)</option>
  24.         <option>ASSISTANT(E) COMMERCIALE</option>
  25.         <option>AUTRE...</option>
  26.         </select>
  27.         </td>
  28.       </tr>
  29.       <tr>
  30.         <td style="text-align: right; width: 111px;">Experience
  31. :</td>
  32.         <td style="width: 298px;">
  33.        
  34.         <select name="Experience">
  35.         <option>Aucune</option>
  36.         <option>- de 1 ans</option>
  37.         <option>De 1 &agrave; 5 ans</option>
  38.         <option>+5 ans</option>
  39.         </select>
  40.         </td>
  41.       </tr>
  42.       <tr>
  43.         <td style="text-align: right; width: 111px;">Ville
  44. :</td>
  45.         <td style="width: 298px;"><input size="10" name="ville"></td>
  46.       </tr>
  47.       <tr>
  48.         <td style="text-align: right; width: 111px;">Pr&eacute;nom
  49. :</td>
  50.         <td style="width: 298px;"><input name="prenom"></td>
  51.       </tr>
  52.       <tr>
  53.         <td style="text-align: right; width: 111px;">Nom :</td>
  54.         <td style="width: 298px;"><input name="NOM"></td>
  55.       </tr>
  56.       <tr>
  57.         <td style="text-align: right; width: 111px;"><span style="font-weight: bold;">E-mail :</span></td>
  58.         <td style="width: 298px;"><input name="e-mail"></td>
  59.       </tr>
  60.       <tr>
  61.         <td style="text-align: right; width: 111px;"><span style="font-weight: bold;">T&eacute;lephone :</span></td>
  62.         <td style="width: 298px;"><input maxlength="13" name="telephone"></td>
  63.       </tr>
  64.       <tr>
  65.         <td style="text-align: right; width: 111px;"><span style="font-weight: bold;">Votre CV</span> :<br>
  66.         <br>
  67.         </td>
  68.         <td style="width: 298px;"><input name="MAX_FILE_SIZE" value="200000" type="hidden">
  69.         <input name="NomFichier" size="15" type="file">&nbsp;<br>
  70. (Format Word, Excel, PDF...)</td>
  71.       </tr>
  72.       <tr>
  73.         <td style="text-align: right; height: 95px; width: 111px;">Commentaire
  74. :<br>
  75.         <br>
  76.         <br>
  77.         <br>
  78.         </td>
  79.         <td style="height: 95px; width: 298px;"><textarea wrap="soft" cols="30" rows="4" name="commentaire"></textarea></td>
  80.       </tr>
  81.    
  82.     </tbody>
  83.  
  84.   </table>
  85.   <div style="text-align: center;"><input name="Envoyer" value="Envoyer" type="submit"></div>
  86. </form>
  87. </body>
  88. </html>


 
 
 
 
et recrutement.php (je l'ai appris comme cela)  
 

Code :
  1. <?php
  2. $sujet = date("d/m/Y H:i:s" )." (nouveaux bien)";
  3. $contenu = "";
  4. $contenu .= "Souhait : ".$_POST['souhait']."\n";
  5. $contenu .= "Experience : ".$_POST['Experience']."\n";
  6. $contenu .= "Prenom : ".$_POST['prenom']."\n";
  7. $contenu .= "Nom : ".$_POST['NOM']."\n";
  8. $contenu .= "E-mail : ".$_POST['e-mail']."\n";
  9. $contenu .= "Telephone : ".$_POST['telephone']."\n";
  10. $contenu .= "Mobile : ".$_POST['Mobile']."\n";
  11. $contenu .= "CV: ".$_POST['NomFichier']."\n";
  12. $contenu .= "Commentaire : ".$_POST['commentaire']."\n";
  13. if(mail("comert33@yahoo.fr", $sujet, $contenu))
  14. {
  15.   print "<b>Mail envoyé
  16. <br>
  17. <a
  18. style=\"text-decoration: underline; font-weight: bold; color: rgb(51, 51, 255);\"
  19. href=\"index.html\">RETOUR à l'accueil</a>
  20. </b>";
  21. }
  22. else
  23. {
  24.   print "<b>Erreur</b>";
  25. }
  26. ?>


 
 
 
Donc je ne comprend pas le premier formulaire.  
Pouvez vous m'aider a modifier le 2ieme formulaire pour qu'il envois des piece jointe comme le 1er formulaire?  
 
cordialement

Liens


Aller à :
Ajouter une réponse
  FORUM Infos-du-Net » Programmation » envoyer piece jointe
 

Liens