Fichier joint recu est vide

Résolu
cs_sidalilo Messages postés 108 Date d'inscription mardi 28 février 2006 Statut Membre Dernière intervention 9 juillet 2013 - 7 nov. 2012 à 14:28
sylvain64520 Messages postés 130 Date d'inscription lundi 11 janvier 2010 Statut Membre Dernière intervention 7 juin 2013 - 13 nov. 2012 à 16:08
bonjour
je veux envoyer un mail avec piece jointe vers ma boite mail yahoo mais le fichier joint qui a été recu dans ma boite email est vide voila ma fonction d'envoi mail:

$boundary='glandouillepas';
//En-têtes du mail
$headers="MIME-Version: 1.0\r\n";
$headers.="Content-Type: multipart/mixed; boundary="$boundary"\r\n";
$headers.="From: ali.driss@htshightechsystems212.com\r\n";


//Corps du mail en commençant par le message principal
$body="--". $boundary ."\n";
$body.="Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body.="SALAM.\n\n";







/* Pièce jointe, on va dire que notre fichier s'appelle bidule.doc et qu'il se situe dans le répertoire courant */
//$fichier=file_get_contents('Doc1.doc');
$fichier1 = fopen("Doc1.doc", "r");
$attachement = fread($fichier1, filesize("Doc1.doc"));
$attachement = chunk_split(base64_encode($attachement));
fclose($fichier1);
/* On utilise aussi chunk_split() qui organisera comme il faut l'encodage fait en base 64 pour se conformer aux standards */
$fichier=chunk_split( base64_encode($attachement) );

//Écriture de la pièce jointe
$body.="--" .$boundary. "\n";
$body.="Content-Type: application/msword; name="Doc1.doc"\r\n";
$body.="Content-Transfer-Encoding: base64\r\n";
$body.="Content-Disposition: attachment; filename="Doc1.doc"\r\n";
$body.="$fichier";

//Fermeture de la frontière
//j'ai essayé avec et sans la fermeture de la frontière à ce niveau
//$body.= "--" . $boundary ."--";


//Fermeture de la frontière
$body.= "--" . $boundary ."--";

//Envoi du mail
if(mail("sedhob1@yahoo.fr", "TEST", $body, $headers)){ echo'envoyer';}else{echo'ERREUR';}

3 réponses

sylvain64520 Messages postés 130 Date d'inscription lundi 11 janvier 2010 Statut Membre Dernière intervention 7 juin 2013
7 nov. 2012 à 14:45
Voici le code que j'avais fais et qui fonctionne :

// Envoie du fichier par mail
$path = "./Uploads";
$file_name = "Doc1.doc";
$boundary = "_".md5(uniqid(rand()));
$email = "TOTO@TOTO.fr";
$subject = "Test";
$message = "";

$attached_file = file_get_contents("$path/$file_name");
$attached_file = chunk_split(base64_encode($attached_file));

$attached = "\n\n". "--" .$boundary . "\nContent-Type: application/rtf; name="$file_name"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename="$file_name"\r\n\n".$attached_file . "--" . $boundary . "--";

$headers ="From: TOTO <TOTO@TOTO.fr> \r\n";
$headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary="$boundary"\r\n";

$body = "--". $boundary ."\nContent-Type: text/plain; charset=ISO-8859-1\r\n".$message . $attached;

mail($email, $subject, $body, $headers);
3
cs_sidalilo Messages postés 108 Date d'inscription mardi 28 février 2006 Statut Membre Dernière intervention 9 juillet 2013
7 nov. 2012 à 15:12
je tien a remercier beaucoup
que le dieu te protege.
le probleme est resolu.

CDT
0
sylvain64520 Messages postés 130 Date d'inscription lundi 11 janvier 2010 Statut Membre Dernière intervention 7 juin 2013
13 nov. 2012 à 16:08
pas d'quoi :)
0
Rejoignez-nous