[PHP] Problème Envoi mail et pièce jointe
supertoms
Messages postés
32
Date d'inscription
Statut
Membre
Dernière intervention
-
rom149 -
rom149 -
Salut à tous !
Alors voila ce qui se passe :
Je rempli un formulaire html.
A la validation, je génère un fichier PDF à partir de ce qui a été entré, je génère aussi un texte sommaire.
J'envoie le tout par mail, avec le pdf en pièce jointe.
Voici le code :
[cpp]<?php
$boundary="voilalafrontierepourseparertexteetpiecejointe";
$nom=$_POST['nomMail'];
$mail=$_POST['mailMail'];
$objet=$_POST['objetMail'];
$message=$_POST['messageMail'];
/////voici la version Mine
$headers = "MIME-Version: 1.0\r\n";
//////ici on détermine le mail en format text
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n\n";
////ici on détermine l'expediteur et l'adresse de réponse
$headers .= "From: $nom <supertoms@neuf.fr>\r\nReply-to : $nom <supertoms@neuf.fr>\nX-Mailer:PHP";
$subject="$objet";
$destinataire="toms@free.fr";
$body="--".$boundary."\n
Content-Type: text/plain; charset=ISO-8859-1\r\n\n
".$message."\n\n";
$fichier=file_get_contents('..\dossier.pdf');
$fichier=chunk_split( base64_encode($fichier));
$body = $body . "--" . $boundary . "\n
Content-Type: application/pdf; name=\"dossier.pdf\"\r\n
Content-Transfer-Encoding: base64\r\n
Content-Disposition: attachment; filename=\"nom_fichier\"\r\n\n
$fichier";
$body = $body . "--" . $boundary ."--";
if (mail($destinataire,$subject,$body,$headers)) {
echo "Votre mail a été envoyé";
} else {
echo "Une erreur s'est produite";
}
?>[/cpp]
Voila, pour info la génération du fichier dossier.pdf fonctionne bien.
Mon problème est le suivant : je reçoi le mail, mais ca ressemble à cette chose horrible :
<strong>DEMANDEUR :</strong><br />monsieur ARFOUILLE Thomas<br /><br />Adresse :<br />sdgs<br />69300 ezg<br /><br />Tél. fixe : 0412345678<br /> Tél. mobil : 0612121212 <br /> Mail : toms@free.fr <br /><br /><strong>ELEVE :</strong><br />Nom : ezgfezdgf <br />Prenom : ezgf <br />Date de naissance : 18/02/2003 <br />Etablissement : ezfve <br />Classe : ezgfez <br /> <br /><strong>MESSAGE OPTIONNEL :</strong><br />ezgfez--voilalafrontierepourseparertexteetpiecejointe
Content-Type: application/pdf; name="dossier.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="nom_fichier"
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAy
IDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVj
b2RlIC9MZW5ndGggNDg2Pj4Kc3RyZWFtCnichVPLctNAELznK+YIh4x39r2cSGJRFYqEIgjui7Ry
...et bien d'autres caractères pendant trèèèès longtemps !
Voila, merci d'avance!
Alors voila ce qui se passe :
Je rempli un formulaire html.
A la validation, je génère un fichier PDF à partir de ce qui a été entré, je génère aussi un texte sommaire.
J'envoie le tout par mail, avec le pdf en pièce jointe.
Voici le code :
[cpp]<?php
$boundary="voilalafrontierepourseparertexteetpiecejointe";
$nom=$_POST['nomMail'];
$mail=$_POST['mailMail'];
$objet=$_POST['objetMail'];
$message=$_POST['messageMail'];
/////voici la version Mine
$headers = "MIME-Version: 1.0\r\n";
//////ici on détermine le mail en format text
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n\n";
////ici on détermine l'expediteur et l'adresse de réponse
$headers .= "From: $nom <supertoms@neuf.fr>\r\nReply-to : $nom <supertoms@neuf.fr>\nX-Mailer:PHP";
$subject="$objet";
$destinataire="toms@free.fr";
$body="--".$boundary."\n
Content-Type: text/plain; charset=ISO-8859-1\r\n\n
".$message."\n\n";
$fichier=file_get_contents('..\dossier.pdf');
$fichier=chunk_split( base64_encode($fichier));
$body = $body . "--" . $boundary . "\n
Content-Type: application/pdf; name=\"dossier.pdf\"\r\n
Content-Transfer-Encoding: base64\r\n
Content-Disposition: attachment; filename=\"nom_fichier\"\r\n\n
$fichier";
$body = $body . "--" . $boundary ."--";
if (mail($destinataire,$subject,$body,$headers)) {
echo "Votre mail a été envoyé";
} else {
echo "Une erreur s'est produite";
}
?>[/cpp]
Voila, pour info la génération du fichier dossier.pdf fonctionne bien.
Mon problème est le suivant : je reçoi le mail, mais ca ressemble à cette chose horrible :
<strong>DEMANDEUR :</strong><br />monsieur ARFOUILLE Thomas<br /><br />Adresse :<br />sdgs<br />69300 ezg<br /><br />Tél. fixe : 0412345678<br /> Tél. mobil : 0612121212 <br /> Mail : toms@free.fr <br /><br /><strong>ELEVE :</strong><br />Nom : ezgfezdgf <br />Prenom : ezgf <br />Date de naissance : 18/02/2003 <br />Etablissement : ezfve <br />Classe : ezgfez <br /> <br /><strong>MESSAGE OPTIONNEL :</strong><br />ezgfez--voilalafrontierepourseparertexteetpiecejointe
Content-Type: application/pdf; name="dossier.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="nom_fichier"
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAy
IDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVj
b2RlIC9MZW5ndGggNDg2Pj4Kc3RyZWFtCnichVPLctNAELznK+YIh4x39r2cSGJRFYqEIgjui7Ry
...et bien d'autres caractères pendant trèèèès longtemps !
Voila, merci d'avance!
A voir également:
- [PHP] Problème Envoi mail et pièce jointe
- Pièce d'identité - Accueil - Services publics
- Programmer envoi mail gmail - Guide
- 1 pièce jointe - Guide
- Envoi mail cci - Guide
- Publipostage mail - Accueil - Word
4 réponses
Pour le probleme, le fait est que Content-Transfer-Encoding: base64\r\n n'est pas bien compris
Il suffit de mettre BASE64 (en majuscule) et tout fonctionne a merveille lors de l'ouverture du fichier joint (plus de souci de decodage ;p)
donc la soluce : Content-Transfer-Encoding: BASE64\r\n
Enjoy
Il suffit de mettre BASE64 (en majuscule) et tout fonctionne a merveille lors de l'ouverture du fichier joint (plus de souci de decodage ;p)
donc la soluce : Content-Transfer-Encoding: BASE64\r\n
Enjoy
rom149
Magique !
J'ai du nouveau !
Je recois la pièce jointe mais acrobat reader me met le message suivant à l'ouverture : Adobe Reader could not open 'dossier.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment end wasn't correctly decoded).
Je recois la pièce jointe mais acrobat reader me met le message suivant à l'ouverture : Adobe Reader could not open 'dossier.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment end wasn't correctly decoded).