Bonjour , Bonsoir ,
J'ai un gros soucis pour ma newsletter , impossible d'envoyer du contenu texte sans perdre le html
Edit : Je pense que le prob provient des headers .. et dans la gestion des pieces jointes ..
1er Code : Envoi un mail html correctement sans mail text/plain
2eme Code : Envoi Html + Brut : pb de visionnage html , ok concernant le mail text/plain si on demande à notre client de mail de le visionner, MAIS le code html ne marche pas , mais je vois bien pourtant les balises html dans le code dans les sources du mails... meme les images + pdf encodés .. ( d'ailleurs ils ne sont meme pas comptabilisé dans la taille du message ? header foireux ...?! ) arf
Merci d'avance
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
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 <?php //BLABLA mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("Mailing"); $iquery = "select * from conf"; $squery = mysql_query($iquery); $donnees = mysql_fetch_array($squery); $linkimage1 = $donnees['linkimage1']; $linkimage2 = $donnees['linkimage2']; $Image_Formation_1 ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation_image_1.jpg"; $Image_Formation_2 ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation_image_2.jpg"; $PDF ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation.pdf"; $Name_Image_Formation_1 = "formation_image_1.jpg"; $Name_Image_Formation_2 = "formation_image_2.jpg"; $Name_PDF = "formation.pdf"; $MailFrom="XXX YYY - Formation"; $MailFromAdr="formation@DOMAINE.fr"; ///FIN BLABLA //DEPART $CID = md5(uniqid (rand(), 1)); $mime_boundary = "" . md5(uniqid(mt_rand(), 1)); $Header= "From:$MailFrom<$MailFromAdr>\n"; // $Header.= "X-mailer: PHP/" . phpversion(). "\n"; $Header.= "MIME-Version: 1.0\n"; $Header.= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"; type=\"text/plain\"\n"; $MailBody = "--".$mime_boundary."\n"; $MailBody.= "Content-Type: Text/HTML; charset=iso-8859-1"; $MailBody.= "Content-Transfer-Encoding: quoted-printable\n\n"; $MailBody.= "<html><head></head><body><br><br>"; $MailBody.= "<br>"; $MailBody .= "<div align=\"center\"><a href=\"".$linkimage1."\"><img src=\"formation_image_1.jpg\" height=\"1054\" width=\"745\" border=0 alt=\"formation image 1\"></a><br></div>"; $MailBody .= "<div align=\"center\"><a href=\"".$linkimage2."\"><img src=\"formation_image_2.jpg\" height=\"1054\" width=\"745\" border=0 alt=\"formation image 2\"></a><br></div>"; //$MailBody .= "<div align=\"center\"><img src=\"cid:$file_id\" alt=\"calor\"><br></div>"; //$message .= "<img src=\"cid:$file_id\" alt=\"calor\"><br>"; $MailBody .= "<br>Pour vous desinscrire envoyer un courrier electronique à desabo@DOMAINE.fr."; $MailBody.= "<br><br></body></html>\n\n"; $MailBody .= "\n \n \r Si vous ne visualisez pas correctement ce message , rendez-vous a l adresse suivante ".$linkimage1."\n\n"; $MailBody.= "--".$mime_boundary."\n"; $MailBody = str_replace("formation_image_1.jpg", "cid:$CID.$Name_Image_Formation_1", $MailBody); $MailBody = str_replace("formation_image_2.jpg", "cid:$CID.$Name_Image_Formation_2", $MailBody); $fp = fopen ($Image_Formation_2, "rb"); $str = fread ($fp, filesize ($Image_Formation_2)); $datar = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: image/jpg\n"; $content.= "Content-ID: <$CID.$Name_Image_Formation_2>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_Image_Formation_2\"\n\n"; fclose($fp); $content.= $datar."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; $fp = fopen ($Image_Formation_1, "rb"); $str = fread ($fp, filesize ($Image_Formation_1)); $data = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: image/jpg\n"; $content.= "Content-ID: <$CID.$Name_Image_Formation_1>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_Image_Formation_1\"\n\n"; fclose($fp); $content.= $data."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; $fp = fopen ($PDF, "rb"); $str = fread ($fp, filesize ($PDF)); $dataz = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: application/pdf\n"; $content.= "Content-ID: <$CID.$Name_PDF>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_PDF\"\n\n"; fclose($fp); $content.= $dataz."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("Mailing"); $iquery = "select sujet from conf"; $squery = mysql_query($iquery); $donnees = mysql_fetch_array($squery); $MailToSubject = $donnees['sujet']; $MailTo ="xxx@xxx.fr"; //$MailTo ="yyy@yyy.com"; mail($MailTo, $MailToSubject, $MailBody, $Header,"-fformation@DOMAINE.fr"); ?>
le code qui ne fonctionne pas
( le contenu alternative brut marche , mais le code html ne fonctionne plus .. le contenu du mail contient bien les pj mais dans mon client de messagerie la taille ne les comptabilise pas .. ! bizarre
ps : Merci à ceux qui on lu le message mais n'ont pas répondu -> vous avez qd meme pris la peine de lire !
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
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 <?php //BLABLA mysql_connect("localhost", "root", "mdpxxx"); mysql_select_db("Mailing"); $iquery = "select * from conf"; $squery = mysql_query($iquery); $donnees = mysql_fetch_array($squery); $linkimage1 = $donnees['linkimage1']; $linkimage2 = $donnees['linkimage2']; $Image_Formation_1 ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation_image_1.jpg"; $Image_Formation_2 ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation_image_2.jpg"; $PDF ="/var/www/prod/demo.DOMAINE.fr/file-mailing/formation.pdf"; $Name_Image_Formation_1 = "formation_image_1.jpg"; $Name_Image_Formation_2 = "formation_image_2.jpg"; $Name_PDF = "formation.pdf"; $MailFrom="XXX YYY - Formation"; $MailFromAdr="formation@DOMAINE.fr"; ///FIN BLABLA //DEPART $CID = md5(uniqid (rand(), 1)); $mime_boundary = "" . md5(uniqid(mt_rand(), 1)); $Header= "From:$MailFrom<$MailFromAdr>\n"; // $Header.= "X-mailer: PHP/" . phpversion(). "\n"; $Header.= "MIME-Version: 1.0\n"; $Header.= "Content-Type: multipart/alternative; boundary=\"".$mime_boundary."\"; \n"; $MailBody = 'This is a multi-part message in MIME format.'."\n\n"; $MailBody.= "--".$mime_boundary."\n"; $MailBody.= "Content-Type: Text/plain; charset=iso-8859-1\n"; //windows-1252 $MailBody.= "Content-Transfer-Encoding: 8bit\n\n"; $MailBody.= "Coucou message test\n\n"; $MailBody .= "--".$mime_boundary."\n"; $MailBody.= "Content-Type: Text/HTML; charset=iso-8859-1"; $MailBody.= "Content-Transfer-Encoding: quoted-printable\n\n"; $MailBody.= "<html><head></head><body><br><br>"; $MailBody.= "<br>"; $MailBody .= "<div align=\"center\"><a href=\"".$linkimage1."\"><img src=\"formation_image_1.jpg\" height=\"1054\" width=\"745\" border=0 alt=\"formation image 1\"></a><br></div>"; $MailBody .= "<div align=\"center\"><a href=\"".$linkimage2."\"><img src=\"formation_image_2.jpg\" height=\"1054\" width=\"745\" border=0 alt=\"formation image 2\"></a><br></div>"; //$MailBody .= "<div align=\"center\"><img src=\"cid:$file_id\" alt=\"calor\"><br></div>"; //$message .= "<img src=\"cid:$file_id\" alt=\"calor\"><br>"; $MailBody .= "<br>Pour vous desinscrire envoyer un courrier electronique à desabo@DOMAINE.fr."; $MailBody.= "<br><br></body></html>\n\n"; $MailBody .= "\n \n \r Si vous ne visualisez pas correctement ce message , rendez-vous a l adresse suivante ".$linkimage1."\n\n"; $MailBody.= "--".$mime_boundary."\n"; $MailBody = str_replace("formation_image_1.jpg", "cid:$CID.$Name_Image_Formation_1", $MailBody); $MailBody = str_replace("formation_image_2.jpg", "cid:$CID.$Name_Image_Formation_2", $MailBody); $fp = fopen ($Image_Formation_2, "rb"); $str = fread ($fp, filesize ($Image_Formation_2)); $datar = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: image/jpg\n"; $content.= "Content-ID: <$CID.$Name_Image_Formation_2>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_Image_Formation_2\"\n\n"; fclose($fp); $content.= $datar."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; $fp = fopen ($Image_Formation_1, "rb"); $str = fread ($fp, filesize ($Image_Formation_1)); $data = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: image/jpg\n"; $content.= "Content-ID: <$CID.$Name_Image_Formation_1>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_Image_Formation_1\"\n\n"; fclose($fp); $content.= $data."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; $fp = fopen ($PDF, "rb"); $str = fread ($fp, filesize ($PDF)); $dataz = chunk_split(base64_encode($str)); $content = ""; $content.= "Content-Type: application/pdf\n"; $content.= "Content-ID: <$CID.$Name_PDF>\n"; $content.= "Content-Transfer-Encoding: base64\n"; $content.= "Content-Disposition: inline; filename=\"$Name_PDF\"\n\n"; fclose($fp); $content.= $dataz."\n"; $MailBody.= $content; $MailBody.= "--".$mime_boundary."\n"; mysql_connect("localhost", "root", "mdpxxx"); mysql_select_db("Mailing"); $iquery = "select sujet from conf"; $squery = mysql_query($iquery); $donnees = mysql_fetch_array($squery); $MailToSubject = $donnees['sujet']; $MailTo ="xxx@xxx.fr"; //$MailTo ="yyy@yyy.com"; mail($MailTo, $MailToSubject, $MailBody, $Header,"-zzz@xxx.fr"); ?>et donc essayer de m'aider
ps1 at admin @ modo : y a t il une purge des comptes car mon compte ne marche plus ! ( old compte )
Partager