Bonjour,

je souhaiterais envoyer un .pdf en pièce jointe dans un mail en utilisant la fonction mail() de php

je reçois bien un mail ayant des fichiers en pièces jointes mais pas mon .pdf . J'ai lu sur différents sites que c'était lié à un problème d'encodage mais je ne vois pas trop quoi faire.

Voici mon code :

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
 
if($nni!="")
{
echo "hello world";
$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: $type; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= "test";
$msg .= "\r\n";
 
$attachment = fread($fp, filesize('C:\avancement\\'.$nni.'.pdf'));
fclose($fp);
 
$attachment = chunk_split(base64_encode($attachment));
 
//$attachment = $fp;
 
 
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: $type2; name=\"$attachment\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: inline; filename=\"$attachment\"\r\n";
$msg .= "\r\n";
$msg .=$attachment . "\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
 
 
$destinataire = $email_dest;
$dest2 = $email_manag;
$expediteur   = "moi";
//$reponse      = $expediteur;
echo "Mail envoyé à $destinataire";
 
mail($destinataire, "test", $msg,
     "Reply-to: $reponse\r\nFrom: $expediteur\r\n".$header);
 
}
Je débute dans l'utilisation de cette fonction, et je ne vois pas trop quoi faire pour arranger ça.

Merci.