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 :

php envoi de mail boundary


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Novembre 2007
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 274
    Points : 114
    Points
    114
    Par défaut
    Bonjour à tous,

    Je viens vers vous car j'ai un souci avec l'envoi de mail en php, je vous explique.

    J'utilise une class php SMTP pour l'envoi de mail avec pièce jointe, tout ce passe bien, sauf que j'ai eu un ou deux retour me disant que le mails étais bizar. le boudary en réalité est afficher dans le mail et contient à la place de la pièce jointe :
    Cordialement. --------------Boundary-00=_dbe87800000000000000 Content-Type: application/pdf; name="Namur-13-06-2013.pdf" Content-Disposition: attachment Content-Transfer-Encoding: base64 JVBERi0xLjcKMyAwIG9iago8PC9UeXBlIC9QYWdlIC9QYXJlbnQgMSAwIFIgL01lZGlhQm94IFsw IDAgNTk1LjI4IDg0MS44OV0gL0dyb3VwIDw8IC9UeXBlIC9Hcm91cCAvUyAvVHJhbnNwYXJlbmN5 IC9DUyAvRGV2aWNlUkdCID4+IC9SZXNvdXJjZXMgMiAwIFIKL0NvbnRlbnRzIDQgMCBSPj4gZW5k b2JqCjQgMCBvYmoKPDwvRmlsdGVyIC9GbGF0ZURlY29kZSAvTGVuZ3RoIDgxMTM+PiBzdHJlYW0K eJztnVtz20a2hd/9K/B2ZqocCo2+P9rO5YwrSWUmKuchkwfGQmzmUKRDifEkvzj+F6ebQINgLy7J Nxkt1tRMlLTRkHfvDfT6ADQW6pm21euqqZ5WdfVr9eNP4V8X4Z+vKjGr67p68eDxeXX2pahEHdrV +S/VF+cP6vfbKW46f522+f2mbK9339KMt9Qzb3Q1/rk51u19/tJ61oT/Tj9N+Hn0V/+321t3+7jH wX+3wAHrpazGP48m/r/d3q/b9AUueUvJlTuBbtMXuOQtJVfuBLpNX+CSt5RcuRPoNn2BS95ScuVO oNv0BS55S8mVO4Fu0xe45C0lV+4Euk1f4JK3lFy5E+g2fYFL3lJy5U6g2/QFLnlLyZU7gW7TF7jk LSVX7gS6TV/gkreUXLkT6DZ9gUveUnLlTqDb9AUueUvJlTuBbtMXuOQtJVfuBLpNX+CSt5RcuRPo Nn2BS95ScuVOoNv0BS55S8mVO4Fu0xe45C0lV+4Euk1f4JK3lFy5E+g2fYFL3lJy5U6g2/QFLnlL yZU7gW7TF7jkLSVX7gS6TV/gkre...... etc...
    maintenant ca n'arrive que chez une ou deux personne tous les autres le reçoivent comme il faut.

    Je pense pour un problème avec leur boite mail puisque les autre le reçoive nickel, mais sait-on jamais que mon boundary soit le problème. mais je penche pour une restriction dans leurs boite mail pour les mail html/multipart avec pièce jointe.

    Quand pensez-vous ?

    Bonjour à tous,

    Je viens faire un petit up et vous fournir le formation de mon header, car le problème semble venir de là, venant d'une classe je vous fourni la seule fonction qui génère du header.

    Pour infos le fichiers est encodé en utf-8 et les données aussi
    Code PHP : 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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
     
    <?php
    //**************************************************************************
        // Entêtes (Headers)
        //**************************************************************************
        public function headers(){
    		// Id unique
    		$Boundary1 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
    		$Boundary2 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
    		$Boundary3 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';       
     
            $header = '';
            $No_body = 0;
     
            // Adresse de l'expéditeur (format : Nom <adresse_mail>)
            if(!empty($this->From)){
                $header .= 'X-Sender: '.$this->From."\n";// Adresse réelle de l'expéditeur
            }
    		// La version mime
            if(!empty($this->MIME)){
                $header .= 'MIME-Version: '.$this->MIME."\n";
            }
            $header .= sprintf("Message-ID: <%s@%s>%s", md5(uniqid(time())), $this->NomDuDomaine, "\n")
            .'Date: '.date('r')."\n"
            .'Content-Type: Multipart/Mixed;'."\n"
            .'  boundary="'.$Boundary1.'"'."\n"
            // Logiciel utilisé pour l' envoi des mails
    		.'X-Mailer: PHP '.phpversion()."\n";
    		// Adresse de l'expéditeur (format : Nom <adresse_mail>)
            if(!empty($this->From)){
                if(!empty($this->FromName)){
                    $header .= 'From: "'.$this->FromName.'"';
                }else{
                    $header .= 'From: ';
                }
                $header .= '<'.$this->From.">\n";
    		}
    		$header .= 'X-FID: FLAVOR00-NONE-0000-0000-000000000000'."\n";
     
    		// Priorité accordée au mail (valeur allant de 1 pour Urgent à 3 pour normal et 6 pour bas)		
            if(!empty($this->Priority)){
                $header .= 'X-Priority: '.$this->Priority."\n";
            }
    		// To	
            if(!empty($this->To)){// A
                $header .= 'To: '.$this->To."\n";
            }else{
                $No_body++;// Personne
            }
            // Cc
            if(!empty($this->Cc)){// Copie du mail
                $header .= 'Cc: '.$this->Cc."\n";
            }else{
                $No_body++;// Personne
            }
            // Bcc
            if(empty($this->Bcc)){// Blind Carbon Copy, c' est à dire que les adresses qui sont contenue ici seront invisibles pour tout le monde
                $No_body++;// Personne
            }
            // Sujet
            if(!empty($this->Sujet)){
                $header .= 'Subject: '.$this->Sujet."\n";
            }
            if(!empty($this->Confimation_reception)){// Adresse utilisée pour la réponse au mail
                $header .= 'Disposition-Notification-To: <'.$this->Confimation_reception.'>'."\n";
            }
    		// ReplyTo
    		if(!empty($this->ReplyTo) && $this->ReplyTo !== $this->From && $this->ReplyTo !== 'root@localhost'){// Adresse utilisée pour la réponse au mail
                $header .= 'Reply-to: '.$this->ReplyTo."\n"
                .'Return-Path: <'.$this->ReplyTo.">\n";
            }
            if(!IsSet($_SERVER['REMOTE_ADDR'])){$_SERVER['REMOTE_ADDR'] = '127.0.0.1';}
            if(!IsSet($_SERVER['HTTP_X_FORWARDED_FOR'])){$_SERVER['HTTP_X_FORWARDED_FOR'] = '';}
            if(!IsSet($_SERVER['HTTP_USER_AGENT'])){$_SERVER['HTTP_USER_AGENT'] = 'Internet Explorer';}
            if(!IsSet($_SERVER['HTTP_ACCEPT_LANGUAGE'])){$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'Fr-fr';}
            $host = 'localhost';
            if(function_exists('gethostbyaddr') && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1'){$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);}
            $header .= 'X-Client-IP: '.$_SERVER['REMOTE_ADDR']."\n"
    		.'X-Client-PROXY: '.$_SERVER['HTTP_X_FORWARDED_FOR']."\n"
    		.'X-Client-Agent: '.$_SERVER['HTTP_USER_AGENT']."\n"
    		.'X-Client-Host: '.$host."\n"
    		.'X-Client-Language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE']."\n"
    		.'Organization: '.$this->org."\n"
    		."\n\n\n"
    		.'--'.$Boundary1."\n"
    		.'Content-Type: Multipart/Alternative;'."\n"
    		.'  boundary="'.$Boundary3.'"'."\n"
    		."\n\n"
    		.'--'.$Boundary3."\n";
    		if($this->ContentType === 'txt' || $this->ContentType === 'txt/html'){
    			$header .= 'Content-Type: Text/Plain;'."\r\n"
    			.'  charset="'.$this->ISO.'"'."\r\n"
    			.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
    			."\r\n";
    			if($this->ContentType === 'txt'){
    				$header .= $this->Body."\r\n";
    			}else{
    				$header .= $this->Body_txt."\r\n";
    			}
    		}elseif($this->ContentType === 'html' || $this->ContentType === 'txt/html'){
    			if($this->ContentType === 'txt/html'){
    				$header .= '--'.$Boundary3."\r\n";
    			}
    			$header .= 'Content-Type: Text/HTML;'."\r\n"
    			.'  charset="'.$this->ISO.'"'."\r\n"
    			.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
    			."\r\n"
    			.'<html><head>'."\r\n"
    			.'<meta http-equiv="Content-LANGUAGE" content="French" />'."\r\n"
    			.'<meta http-equiv="Content-Type" content="text/html; charset='.$this->ISO.'" />'."\r\n"
    			.'</head>'."\r\n"
    			.'<body>'."\r\n"
    			.$this->Body."\r\n"
    			.'</body></html>'."\r\n"
    			.'--'.$Boundary3.'--'."\r\n";
    		}else{
    			$header .= 'Content-Type: '.$this->ContentType.';'."\r\n"
    			.'  charset="'.$this->ISO.'"'."\r\n"
    			.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
    			."\r\n"
    			.$this->Body."\r\n";	
    		}
    		$header .= "\n";
     
    		// On joint le ou les fichiers
    		if($this->File_joint){
    			foreach($this->File_joint as $file_name => $file){
    		        $header .= '--'.$Boundary1."\n"
    				.'Content-Type: '.$file['mime'].';'."\n"
    				.'  name="'.$file_name.'"'."\n"
    				.'Content-Disposition: attachment'."\n"
    				.'Content-Transfer-Encoding: BASE64'."\r\n"
    				."\n"
    				.chunk_split(base64_encode(file_get_contents($file['url'])))."\n"
    				."\n\n";
    			}
    		}
    		$header .= '--'.$Boundary1.'--';
     
            if($No_body === 3){
                $this->erreur = 'Le mail n' a pas de destinataire !!!';
                return false;
            }
            return $header;
        }
    ?>

    Merci d'avance de votre aide

  2. #2
    Membre régulier
    Homme Profil pro
    Inscrit en
    Novembre 2007
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 274
    Points : 114
    Points
    114
    Par défaut
    Bonjour à tous,

    après moult recherche j'ai réécris ma méthode headers et tout marche :p

    Voici mon nouveau header
    Code PHP : 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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
     
    <?
        public function headers(){
     
            // a random hash will be necessary to send mixed content
            $separator = md5(time());
     
            // carriage return type (we use a PHP end of line constant)
            $eol = PHP_EOL;
     
            // Si == 3 alors il n'y a pas de destinataire
            $No_body = 0;
     
            // main header (multipart mandatory)
            $header  = "";
            if(!empty($this->From)){
                if(!empty($this->FromName)){ $header .= 'From: "'.$this->FromName.'"'; }
                else{ $header .= 'From: '; }
                $header .= '<'.$this->From.">".$eol;
    		}
            $header .= "X-Mailer: PHP ".phpversion().$eol;
    		$header .= 'X-Sender: '.$this->From.$eol;
     
            if(!empty($this->Priority)){
                $header .= 'X-Priority: '.$this->Priority.$eol;
            }
            // To
            if(!empty($this->To)){ $header .= 'To: '.$this->To.$eol;
            }else{ $No_body++; }
            // Cc
            if(!empty($this->Cc)){ $header .= 'Cc: '.$this->Cc.$eol; }
            else{ $No_body++; }
            // Bcc
            if(!empty($this->Bcc)){ $header .= 'Bcc: '.$this->Bcc.$eol;}
            else{ $No_body++; }
            // Sujet
            if(!empty($this->Sujet)){ $header .= 'Subject: '.$this->Sujet.$eol; }
            else{ $header .= 'Subject: Pas de sujet'; }
            // ReplyTo
    		if(!empty($this->ReplyTo) && $this->ReplyTo !== $this->From && $this->ReplyTo !== 'root@localhost'){// Adresse utilisée pour la réponse au mail
                $header .= 'Reply-to: '.$this->ReplyTo.$eol;
                $header .= 'Return-Path: <'.$this->ReplyTo.">".$eol;
            }
            $header .= 'Date: '.date('r').$eol;
     
            $header .= "MIME-Version: 1.0".$eol; 
            $header .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
            $header .= "Content-Transfer-Encoding: 8bit".$eol;
            $header .= "This is a MIME encoded message.".$eol.$eol;
     
            // message
            $header .= "--".$separator.$eol;
            $header .= "Content-Type: text/html; charset=\"".$this->ISO."\"".$eol;
            $header .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
            $header .= $this->Body.$eol.$eol;
     
    		// On joint le ou les fichiers
    		if($this->File_joint){
    			foreach($this->File_joint as $file_name => $file){
    		        $attach = chunk_split(base64_encode(file_get_contents($file['url'])));
                    $header .= "--".$separator.$eol;
                    $header .= "Content-Type: ".$file['mime']."; name=\"".$file_name."\"".$eol; 
                    $header .= "Content-Transfer-Encoding: base64".$eol;
                    $header .= "Content-Disposition: attachment".$eol.$eol;
                    $header .= $attach.$eol.$eol;
                    $header .= "--".$separator."--";
    			}
    		}
     
            if($No_body === 3){
                $this->erreur = 'Le mail n' a pas de destinataire !!!';
                return false;
            }
            return $header;
        }
    ?>
    Donc problème résolu, merci.

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 24
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 6
    Points : 2
    Points
    2
    Par défaut php envoi de mail boundary
    Bonjour à tous,
    J'ai aussi un petit soucis evec ( mail boundary)
    Je me sert d'incredimail et tous mes contact utilisant autres qu' incredimail ou sur smartphone recois des mails bizare comme d'écrit plus haut.
    Je ne parviens pas à résoudre ce problème, je suis sous windows 10, je ne sais pas si il est pour quelque chose ?
    un tout grand merci pour votre aide.

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Novembre 2007
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 274
    Points : 114
    Points
    114
    Par défaut
    Citation Envoyé par sergiosat Voir le message
    Bonjour à tous,
    J'ai aussi un petit soucis evec ( mail boundary)
    Je me sert d'incredimail et tous mes contact utilisant autres qu' incredimail ou sur smartphone recois des mails bizare comme d'écrit plus haut.
    Je ne parviens pas à résoudre ce problème, je suis sous windows 10, je ne sais pas si il est pour quelque chose ?
    un tout grand merci pour votre aide.
    Bonjour,

    quelle méthode utilise tu pour envoyer tes mails ?
    (smtp, imap)
    On parle bien de mail envoyé depuis un site web en php hein ? car si je ne me trompe pas incredimail est un client mail (comme outlook, thunderbird, etc...), dans ce cas tu n'est pas au bon endroit

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Script php envoi de mail n'envoie rien
    Par the.co dans le forum Langage
    Réponses: 3
    Dernier message: 21/01/2014, 06h39
  2. Souci PHP envoi de mail
    Par Invité dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 18/09/2012, 23h42
  3. PHP envoi de mail
    Par T4GAD4 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 10
    Dernier message: 04/07/2012, 09h55
  4. Réponses: 3
    Dernier message: 22/02/2010, 13h43
  5. php envoie de mail
    Par pratheep dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 02/06/2009, 17h14

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