Statut : Non résoluMail avec fichier joint / MIME
Posté par
Philip, le mardi 4 novembre 2003 à 10:13:32 Auteur: Philip
Date: 03-11-2003 18:23
Bonjour,
J'utilise une fonction qui permet d'envoyer un mail avec une partie texte et un fichier joint.
Seulement voilà selon le logiciel de messagerie des destinataires ça ne marche pas toujours!
Par exemple les utilisateurs de Lotus Notes ou de certaines version de Outlook Express ne reçoivent pas le fichier en fichier joint mais sa source dans le corps du texte!
En analysant les sources des différents messages il semble que les sauts de lignes \r\n soient mal interprétés ('doublage' des sauts de lignes visible sous Word et ci-dessous mais pas sous Notepad)...
Sur mon PC je teste avec Outlook Express 5 et Outlook 97 et tout marche impeccable, je n'arrive pas à produire ces erreurs!
Quelqu'un a une idée?
----------------------------------------------
Ci dessous ma fonction d'envoi de mail et la source d'un message d'un destinataire chez qui ça ne marche pas.
function mail_fichier($to,$from, $subject, $body, $file, $mimetype, $localfilename)
{
// Headers
$boundary = "------ =_NextPart_".strtoupper(md5(uniqid(rand())));
//From
$header = "From: $from\r\n";
//MIME Version
$header .= "MIME-Version: 1.0\r\n";
// Type
$header .= "Content-Type: multipart/mixed;boundary=\"$boundary\"\r\n";
// TEXT
$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 .= $body;
$msg .= "\r\n";
// FILE (if there is one)
if ($file != "")
{
//read attachment
$fp = fopen($file, "r");
$attachment = fread($fp, filesize($file));
fclose($fp);
// RFC 2045
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: $mimetype; name=\"$localfilename\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$localfilename\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
}
//END OF MAIL
$msg .= "--$boundary--\r\n\r\n";
mail($to, $subject, $msg, $header);
}
Source de message qui ne marche pas :
X-F: <x@xx.com> Mon Nov 03 11:44:37 2003
Received: from lwm002b1.loco-web.net [213.200.100.194] by xx.org
(SMTPD32-6.05) id A5F33660006E; Mon, 03 Nov 2003 11:44:35 -0500
Received: (qmail 12627 invoked by uid 103); 3 Nov 2003 16:55:06 -0000
Date: 3 Nov 2003 16:55:06 -0000
Message-ID: <20031103165506.12626.qmail@lwm002b1.loco-web.net>
To: x@x.org
Subject: Test fonction mail
From: Philip <philip_bessiere@yahoo.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary="------ =_NextPart_D4E18FC38CD0D030189852D714D858D3"
X-RCPT-TO: <fstaub@icriforum.org>
X-UIDL: 364355682
Status: U
-------- =_NextPart_D4E18FC38CD0D030189852D714D858D3
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding:8bit
Ce mail a une image .jpg en fichier joint
-------- =_NextPart_D4E18FC38CD0D030189852D714D858D3
Content-Type: image/pjpeg; name="rond.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="rond.jpg"
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkz
ODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2Nj
Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAAhABsDASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm
p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5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