|
|
|
|
Bonjour,
Voilà mon problème : j'arrive à envoyer une pièce jointe mais lorsque je veux en envoyer une deuxième dans le même mail ca ne marche pas.
Ca ne joint qu'un seul fichier ! Comment faire ?
Voici le bout de mon code traitant l'envoi du mail avec les pièces jointes :
$boundary = "-----=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n"; $msg .= "--$boundary\r\n"; $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding:8bit\r\n"; $msg .= "\r\n"; $msg .= "Un client vient d'effectuer une réservation."; $msg .= "\r\n"; $file0 = "contrat.pdf"; $file1 = "facture.pdf"; $fp0 = fopen($file0, "rb"); $fp1 = fopen($file1, "rb"); $attachment0 = fread($fp0, filesize($file0)); $attachment1 = fread($fp1, filesize($file1)); fclose($fp0); fclose($fp1); $attachment0 = chunk_split(base64_encode($attachment0)); $attachment1 = chunk_split(base64_encode($attachment1)); $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file0\"\r\n"; $msg .= "Content-Type: pdf; name=\"$file1\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: attachement; filename=\"$file0\"\r\n"; $msg .= "Content-Disposition: attachement; filename=\"$file1\"\r\n"; $msg .= "\r\n"; $msg .= $attachment0."\r\n"; $msg .= $attachment1."\r\n"; $msg .= "\r\n\r\n"; $msg .= "--$boundary--\r\n"; $destinataire = "crivelli.lucas@gmail.com"; $expediteur = "info@easy-park.ch"; $reponse = $expediteur; $sujet = "Rapport de réservation"; mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header);<code></code>
Configuration: Mac OS X Safari 525.27.1
Salut,
|
Répondre à lucasc
|
Salut Mathieu merci de ton aide,
<?php
mysql_connect('...','...','...');
mysql_select_db('...');
$n_client_login = $_SESSION['n_client_login'];
$email = $donnees['email'];
//******************mail
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= "Ici le message.";
$msg .= "\r\n";
$file1 = "contrat.pdf";
$file2 = "facture.pdf";
$fp = fopen($file1, "rb");
$fp2 = fopen($file2, "rb");
$attachment = fread($fp, filesize($file1));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$attachment2 = fread($fp2, filesize($file2));
fclose($fp2);
$attachment2 = chunk_split(base64_encode($attachment2));
//piece jointe CONTRAT
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: pdf; name=\"$file1\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$file1\"\r\n";
$msg .= "\r\n";
$msg .= $attachment."\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
//piece jointe FACTURE
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: pdf; name=\"$file2\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$file2\"\r\n";
$msg .= "\r\n";
$msg .= $attachment2."\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
$destinataire = "blablabla.com";
$expediteur = "blablabla.ch";
$reponse = $expediteur;
$sujet = "Rapport de réservation";
mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header);
//***********************mail
mysql_close();
?>
Malheureusement ça ne marche pas. Je reçois seulement le fichier contrat.pdf. Merci de ton aide. Lucas |
J'ai moi-même trouvé la réponse :
<?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> <meta http-equiv="Content-Type" content="text/plain; charset=iso-8859-1" /> <title>Document sans titre</title> </head> <body> <?php mysql_connect('...','...','...'); mysql_select_db('...'); $email = $donnees['email']; //******************mail $boundary = "-----=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n"; $msg .= "--$boundary\r\n"; $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding:8bit\r\n"; $msg .= "\r\n"; $msg .= "BLABLABLA."; $msg .= "\r\n"; $file = "fichier1.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier1 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: inline; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $file = "fichier2.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier2 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $msg .= "--$boundary--\r\n"; $destinataire = "monadresse@gmail.com"; $expediteur = "adresse@expediteur"; $reponse = $expediteur; $sujet = "Sujet"; mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header); //***********************mail mysql_close(); ?> </body> </html> Voila ce qui à résolu mon problème. Comme l'a dit Mathieu (presque juste) il y avait $msg .= "--$boundary--\r\n"; //piece jointe FACTURE $msg .= "--$boundary\r\n"; en trop. Comme l'a dit également Mathieu il faut traiter chaque pj comme si il n'y en avait qu'une. et dèrnière astuce. Il faut mettre la première en inline et la deuxième en attachment. Bonne continuation à tous. Lucas PS : merci mathieu |
J'ai moi-même trouvé la réponse :
<!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> <meta http-equiv="Content-Type" content="text/plain; charset=iso-8859-1" /> <title>Document sans titre</title> </head> <body> <?php mysql_connect('...','...','...'); mysql_select_db('...'); //******************mail $boundary = "-----=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n"; $msg .= "--$boundary\r\n"; $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding:8bit\r\n"; $msg .= "\r\n"; $msg .= "BLABLABLA."; $msg .= "\r\n"; $file = "fichier1.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier1 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: inline; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $file = "fichier2.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier2 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $msg .= "--$boundary--\r\n"; $destinataire = "monadresse@gmail.com"; $expediteur = "adresse@expediteur"; $reponse = $expediteur; $sujet = "Sujet"; mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header); //***********************mail mysql_close(); ?> </body> </html> Voila ce qui à résolu mon problème. Comme l'a dit Mathieu (presque juste) il y avait $msg .= "--$boundary--\r\n"; //piece jointe FACTURE $msg .= "--$boundary\r\n"; en trop. Comme l'a dit également Mathieu il faut traiter chaque pj comme si il n'y en avait qu'une. et dèrnière astuce. Il faut mettre la première en inline et la deuxième en attachment. Bonne continuation à tous. Lucas PS : merci mathieu |
J'ai moi-même trouvé la réponse :
<!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> <meta http-equiv="Content-Type" content="text/plain; charset=iso-8859-1" /> <title>Document sans titre</title> </head> <body> <?php mysql_connect('...','...','...'); mysql_select_db('...'); //******************mail $boundary = "-----=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n"; $msg .= "--$boundary\r\n"; $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding:8bit\r\n"; $msg .= "\r\n"; $msg .= "BLABLABLA."; $msg .= "\r\n"; $file = "fichier1.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier1 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: inline; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $file = "fichier2.pdf"; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); //piece jointe fichier2 $msg .= "--$boundary\r\n"; $msg .= "Content-Type: pdf; name=\"$file\"\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n"; $msg .= "\r\n"; $msg .= $attachment."\r\n"; $msg .= "\r\n\r\n"; $msg .= "--$boundary--\r\n"; $destinataire = "monadresse@gmail.com"; $expediteur = "adresse@expediteur"; $reponse = $expediteur; $sujet = "Sujet"; mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header); //***********************mail mysql_close(); ?> </body> </html> Voila ce qui à résolu mon problème. Comme l'a dit Mathieu (presque juste) il y avait $msg .= "--$boundary--\r\n"; //piece jointe FACTURE $msg .= "--$boundary\r\n"; en trop. Comme l'a dit également Mathieu il faut traiter chaque pj comme si il n'y en avait qu'une. et dèrnière astuce. Il faut mettre la première en inline et la deuxième en attachment. Bonne continuation à tous. Lucas PS : merci mathieu |