IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Envoi de plusieurs pièces jointes


Sujet :

Langage PHP

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut Envoi de plusieurs pièces jointes
    Bonjour,
    J'ai récement trouver un formulaire avec envoi de pièce jointe qui fonctionne, je voudrais maintenant le perfectionner en proposant l'envoi de 5 pièce jointe sauf que .... je sais pas ce qu'il faut rajouter en php , je connais le php mais pas du tout les expressions pour ce qui est traitement d'un fichier.

    Voila ma page index.htm qui contient le formulaire html :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <form name="contact" method="post" action="contactok.php" enctype="multipart/form-data">
    Nom :<input type="text" name="nom" size="20"></p>
      <p>Email<input type="text" name="mail" size="20"></p>
      <p>Message<input type="text" name="message" size="20"></p>
     
    <input type=file size=40 name="attach">
    <input type=file size=40 name="attach2">
     
      <p>&nbsp;</p>
      <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
    </form>

    ET maintenant la page php qui traite les informations :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <?
     
    	// ADRESSE DU DESTINATAIRE
    	$to="xxxxxx@gmail.com";
     
    //
     
    	// SUJET DU MESSAGE
    	$sujet=".Message.";
     
    	// ENTETES
    	$entetes="From:$nom $prenom<info@coco-photocop.fr>\r\n";
     
    	// MESSAGE
    	$msg.="\nNom : $nom\n";
    	$msg.="E mail : $mail\n";
    	$msg.="\nMessage :\n\n$message";
     
    	$msg = stripslashes($msg); 
     
     
     
    	if (is_uploaded_file($attach)) {
        $file = fopen($attach, "r");
        $contents = fread($file, $attach_size);
        $encoded_attach = chunk_split(base64_encode($contents));
        fclose($file);
     
       $entetes.= "MIME-version: 1.0\n";
       $entetes.= "Content-type: multipart/mixed; ";
       $entetes.= "boundary=\"Message-Boundary\"\n";
       $entetes.= "Content-transfer-encoding: 7BIT\n";
     
        $body_top = "--Message-Boundary\n";
        $body_top .= "Content-type: text/plain; charset=US-ASCII\n";
        $body_top .= "Content-transfer-encoding: 7BIT\n";
        $body_top .= "Content-description: Mail message body\n\n";
     
        $msg .= "\n\n--Message-Boundary\n";
        $msg .= "Content-type: $attach_type; name=\"$attach_name\"\n";
        $msg .= "Content-Transfer-Encoding: BASE64\n";
        $msg .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
        $msg .= "$encoded_attach\n";
        $msg .= "--Message-Boundary--\n";
      }
     
    $msg = $body_top.stripslashes($msg);	
     
    	if (mail($to,$sujet,$msg,$entetes))
    	{ ...


    Voila je sais pas comment traiter le 2eme fichier <input type=file size=40 name="attach2">

    Merci d'avance pour vos réponses

  2. #2
    Membre éclairé Avatar de agnaou
    Inscrit en
    Février 2009
    Messages
    289
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Février 2009
    Messages : 289
    Par défaut
    pour je propose que au lieu de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <input type=file size=40 name="attach">
    <input type=file size=40 name="attach2">
    metre ca
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <input type=file size=40 name="attach"  enctype="multipart/form-data"> 
    <input type=file size=40 name="attach2"  enctype="multipart/form-data">

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut
    D'accord, sa me parait bien je pense, mais que faudra t-il que j'écrive dans la page php pour intégrer ma 2eme pièce jointe dans le corps du message envoyé par mail ?

  4. #4
    Membre éclairé Avatar de agnaou
    Inscrit en
    Février 2009
    Messages
    289
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Février 2009
    Messages : 289
    Par défaut
    je vous propose le mem traitement effectuer sur votre premier file
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (is_uploaded_file($attach)) {
        $file = fopen($attach, "r");
        $contents = fread($file, $attach_size);
        $encoded_attach = chunk_split(base64_encode($contents));
        fclose($file);..............

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut
    Donc mon code php serait :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    <?
    	
    	// ADRESSE DU DESTINATAIRE
    	$to="xxxxxx@gmail.com";
     
    //
    	
    	// SUJET DU MESSAGE
    	$sujet=".Message.";
     
    	// ENTETES
    	$entetes="From:$nom $prenom<info@coco-photocop.fr>\r\n";
    	
    	// MESSAGE
    	$msg.="\nNom : $nom\n";
    	$msg.="E mail : $mail\n";
    	$msg.="\nMessage :\n\n$message";
    	
    	$msg = stripslashes($msg); 
    	
    	
    	
    	if (is_uploaded_file($attach)) {
        $file = fopen($attach, "r");
        $contents = fread($file, $attach_size);
        $encoded_attach = chunk_split(base64_encode($contents));
        fclose($file);
    
           if (is_uploaded_file($attach2)) {
        $file2 = fopen($attach2, "r");
        $contents2 = fread($file2, $attach_size2);
        $encoded_attach2 = chunk_split(base64_encode($contents2));
        fclose($file2);
     
       $entetes.= "MIME-version: 1.0\n";
       $entetes.= "Content-type: multipart/mixed; ";
       $entetes.= "boundary=\"Message-Boundary\"\n";
       $entetes.= "Content-transfer-encoding: 7BIT\n";
     
        $body_top = "--Message-Boundary\n";
        $body_top .= "Content-type: text/plain; charset=US-ASCII\n";
        $body_top .= "Content-transfer-encoding: 7BIT\n";
        $body_top .= "Content-description: Mail message body\n\n";
     
        $msg .= "\n\n--Message-Boundary\n";
        $msg .= "Content-type: $attach_type; name=\"$attach_name\"\n";
        $msg .= "Content-Transfer-Encoding: BASE64\n";
        $msg .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
        $msg .= "$encoded_attach\n";
        $msg .= "--Message-Boundary--\n";
      }
    	
    $msg = $body_top.stripslashes($msg);	
     
    	if (mail($to,$sujet,$msg,$entetes))
    	{ ...
    La je pense que le traitement du deuxième fichier est fait mais est-ce qu'il sera incorporer au mail ?

  6. #6
    Membre très actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 483
    Par défaut
    bonjour

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (is_uploaded_file($attach2)) {
        $file2 = fopen($attach2, "r");
        $contents2 = fread($file2, $attach_size2);
        $encoded_attach2 = chunk_split(base64_encode($contents2));
        fclose($file2);
    Tu as en effet généré la variable $encoded_attach2 qui contient les informations de ta pièce jointe.

    Il reste maintenant à ajouter cette pièce jointe à ton mail comme ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $msg .= "\n\n--Message-Boundary\n";
        $msg .= "Content-type: $attach_type; name=\"$attach_name\"\n";
        $msg .= "Content-Transfer-Encoding: BASE64\n";
        $msg .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
        $msg .= "$encoded_attach\n";
        $msg .= "--Message-Boundary--\n";
    En remplaçant $encoded_attach par $encoded_attach2.

    ++

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut
    Alors j'ai observé ce que tu m'a dit et j'ai fait ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    if (is_uploaded_file($attach)) {
        $file = fopen($attach, "r");
        $contents = fread($file, $attach_size);
        $encoded_attach = chunk_split(base64_encode($contents));
        fclose($file);
    	
    	$msg .= "\n\n--Message-Boundary\n"; //
        $msg .= "Content-type: $attach_type; name=\"$attach_name\"\n";
        $msg .= "Content-Transfer-Encoding: BASE64\n";
        $msg .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
        $msg .= "$encoded_attach\n";
        $msg .= "--Message-Boundary--\n";
    	
    	}
    	
    	if (is_uploaded_file($attach2)) { //2eme piece jointe
    	$file2 = fopen($attach2, "r");
    (51)	$contents2 = fread($file2, $attach_size2);
    	$encoded_attach2 = chunk_split(base64_encode($contents2));
    	fclose($file2); 
      
    	$msg .= "\n\n--Message-Boundary\n"; //
    	$msg .= "Content-type: $attach2_type; name=\"$attach2_name\"\n";
    	$msg .= "Content-Transfer-Encoding: BASE64\n";
    	$msg .= "Content-disposition: attachment; filename=\"$attach2_name\"\n\n";
    	$msg .= "$encoded_attach2\n";
    	$msg .= "--Message-Boundary--\n"; 
    	
    	}	
    Sauf que j'obtiens une erreur : "Warning: fread() [function.fread]: Length parameter must be greater than 0 in .... on line 51" j'ai noté la ligne 51 ...

    Si j'essaie de comprendre, il y a un paramètre qui est égal à 0 alors qu'il ne devrait pas ?

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut
    svp, quelqu'un aurait une idée ? ?

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 31
    Par défaut
    bon j'ai trouvé pourquoi cette erreur mais j'arrive pas à interger la 2eme pièce jointe au mail , quel syntaxe il faut ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    if (is_uploaded_file($attach)) {
        $file = fopen($attach, "r");
        $contents = fread($file, $attach_size);
        $encoded_attach = chunk_split(base64_encode($contents));
        fclose($file);
    	
    	$msg .= "\n\n--Message-Boundary\n"; //
        $msg .= "Content-type: $attach_type; name=\"$attach_name\"\n";
        $msg .= "Content-Transfer-Encoding: BASE64\n";
        $msg .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
        $msg .= "$encoded_attach\n";
        $msg .= "--Message-Boundary--\n";
    	
    	}
    	
    	if (is_uploaded_file($attach2)) { //2eme piece jointe
    	$file2 = fopen($attach2, "r");
    	$contents2 = fread($file2, $attach2_size);
    	$encoded_attach2 = chunk_split(base64_encode($contents2));
    	fclose($file2); 
      
    	$msg .= "\n\n--Message-Boundary\n"; //
    	$msg .= "Content-type: $attach2_type; name=\"$attach2_name\"\n";
    	$msg .= "Content-Transfer-Encoding: BASE64\n";
    	$msg .= "Content-disposition: attachment; filename=\"$attach2_name\"\n\n";
    	$msg .= "$encoded_attach2\n";
    	$msg .= "--Message-Boundary--\n"; 
    	
    	}
    voila que faire ?

Discussions similaires

  1. Réponses: 8
    Dernier message: 25/04/2014, 17h30
  2. Envoi de plusieurs pièces jointes dans Lotus Notes
    Par chants1707 dans le forum VBA Access
    Réponses: 0
    Dernier message: 19/04/2011, 23h14
  3. [AC-2003] Envoi mail plusieurs pièces jointes
    Par vversaveau dans le forum VBA Access
    Réponses: 1
    Dernier message: 09/06/2010, 22h00
  4. Réponses: 6
    Dernier message: 14/11/2006, 11h35
  5. Envoi d'un mail avec plusieurs pièces jointes
    Par Wilco dans le forum Composants VCL
    Réponses: 3
    Dernier message: 04/04/2006, 11h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo