Bonjour
J'ai un problème avec mon script, j'arrive à envoyer une piece jointe attacher avec les données d'un formulaire mais apres plusieurs tentative je n'arrive pas à attacher plusieurs pieces jointes ( mon formulaire possede 2 champs de type file .. )
voici mon code fonctionnel pour 1 seul pièce attachée.
$name_file = $_FILES['cv']['name']; $source=$_FILES['cv']['tmp_name']; move_uploaded_file($source, "./".$name_file); $extension=get_extension($name_file); $type="text/plain"; if($type=="doc") { $type="text/vnd.ms-word"; } else if($type=="xls") { $type="text/vnd.ms-excel"; } $type2="image/png"; if($extension=="gif") { $type2="image/gif"; } else if($extension=="bmp") { $type2="image/bmp"; } function get_extension($filename) { $parts = explode('.',$filename); $last = count($parts) - 1; $ext = $parts[$last]; return $ext; } if($_POST['nom']!="") { $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 .= $_POST['nom']; // suite du script $msg .= "\r\n"; if($name_file!="") { $file = $name_file; $fp = fopen($file, "rb"); $attachment = fread($fp, filesize($file)); fclose($fp); $attachment = chunk_split(base64_encode($attachment)); $msg .= "--$boundary\r\n"; $msg .= "Content-Type: $type2; 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"; $msg .= "--$boundary--\r\n"; } $destinataire = "mon_AT_mail.com"; $expediteur = $_POST['email']; $reponse = $_POST['email']; mail($destinataire, 'sujet', $msg, "Reply-to: $reponse\r\nFrom: $expediteur\r\n".$header); } if($name_file!="") { unlink($name_file); } print("<br>\n"); ?>
Peut être qu'une personne pourrait m'éclairer car la je m'en sors pas. Merci