Problème envoi email php avec pièce jointe

maha1987 Messages postés 101 Date d'inscription samedi 4 juin 2011 Statut Membre Dernière intervention 29 avril 2013 - 29 févr. 2012 à 11:05
TychoBrahe Messages postés 1309 Date d'inscription samedi 31 janvier 2009 Statut Membre Dernière intervention 5 juin 2013 - 29 févr. 2012 à 22:38
Bonjour Tout le monde,
je veux envoyer un mail php avec une image jointe ,le problème c'est que j'obtiens dans ma boite reception des code bizarres,
voici mon code
        <?php
        $to      = "monmail@gmail.com"; //Destinataire du message

$from="sqdqsdqs";

$msg  = 'Bonjour,'."\r\n\r\n";

$boundary = "_".md5 (uniqid (rand())); 


$file = "monimage.jpg";
$attached_file = file_get_contents($file);  
$attached_file = chunk_split(base64_encode($attached_file)); 

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

  $headers = "From: " . $from . "\r\n" .
            "Reply-To: " . $from . "\r\n" .
            "X-Mailer: PHP/" . phpversion();
 $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary="$boundary"\r\n";
        $additionalparam = "-r " . $from;
 
 $body = "--". $boundary ."\nContent-Type: text/plain; charset=ISO-8859-1\r\n\n".$msg . $attached; 
 
  $headers = "From: " . $from . "\r\n" .
            "Reply-To: " . $from . "\r\n" .
            "X-Mailer: PHP/" . phpversion();
        $additionalparam = "-r " . $from;

       if(mail($to, $subject, $body, $headers, $additionalparam))
     {
        echo'Votre message a bien été envoyé !';
     }
     else
     {
          echo 'Votre message n\'a pu être envoyé';
     }
?>


le résultat est le suivant:
--_3828d968eacb7c9260b3eb52ec5b6032
Content-Type: text/plain; charset=ISO-8859-1

Bonjour,

--_3828d968eacb7c9260b3eb52ec5b6032
Content-Type: application; name=""
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=""

/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg
SlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMP
FB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEc
ITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgB
WgK8AwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMC
BAMFBQQEAAABfQECAwAEEQUSITFBBhNR

help !!!

3 réponses

abta88 Messages postés 12 Date d'inscription lundi 25 mai 2009 Statut Membre Dernière intervention 16 mars 2012
29 févr. 2012 à 11:18
0
maha1987 Messages postés 101 Date d'inscription samedi 4 juin 2011 Statut Membre Dernière intervention 29 avril 2013
29 févr. 2012 à 14:33
Merci pour votre réponse mais le pb persiste encore
0
TychoBrahe Messages postés 1309 Date d'inscription samedi 31 janvier 2009 Statut Membre Dernière intervention 5 juin 2013 12
29 févr. 2012 à 22:38
Salut

Je te suggère, pour commencer, de revoir la ligne suivante :
$attached = "\n\n". "--" .$boundary . "\nContent-Type: application; name="$file_name"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename="$file_name"\r\n\n".$attached_file . "--" . $boundary . "--"; 

- $file_name n'existe pas
- Il me semble qu'il y a de simple \n à la place de \r\n
- Le Content-Type est mauvais
0
Rejoignez-nous