Fonction mail php la bonne format de header

Résolu/Fermé
safa778 Messages postés 23 Date d'inscription mardi 15 mai 2018 Statut Membre Dernière intervention 27 mai 2018 - 24 mai 2018 à 13:03
safa778 Messages postés 23 Date d'inscription mardi 15 mai 2018 Statut Membre Dernière intervention 27 mai 2018 - 25 mai 2018 à 09:43
Bonjour,

ma fonction mail en php me permet de recuperer les données de l'utilisteur de formulaire de contact avec une piece jointe mais quand j'ai de récuperer les données de l'email sous format html ça marche pas et la piece jointe ne s'ouvre pas voila mon headers code

$headers = "MIME-Version: 1.0\r\n"; 
        $headers.= "From: Et\r\n"; 
        $headers.= "Reply-To: TA" . "\r\n";
        $headers.= "MIME-Version: 1.0" . $passage_ligne;
        $headers.= 'Content-type: text/html; charset=iso-8859-1 \r\n';
        $headers.= 'Content-Type: multipart/mixed; boundary='.$boundary .' '. $passage_ligne;


je dois enlever le type html pour que la piece jointe s'ouvre si nn avec seulement multipart mixed les balise html serons visible quans je recu les emails

1 réponse

jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 4 650
24 mai 2018 à 22:46
Bonjour,

Exemple
 $filename = 'myfile';
    $path = 'your path goes here';
    $file = $path . "/" . $filename;

    $mailto = 'mail@mail.com';
    $subject = 'Subject';
    $message = 'My message';

    $content = file_get_contents($file);
    $content = chunk_split(base64_encode($content));

    // a random hash will be necessary to send mixed content
    $separator = md5(time());

    // carriage return type (RFC)
    $eol = "\r\n";

    // main header (multipart mandatory)
    $headers = "From: name <test@test.com>" . $eol;
    $headers .= "MIME-Version: 1.0" . $eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
    $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
    $headers .= "This is a MIME encoded message." . $eol;

    // message
    $body = "--" . $separator . $eol;
    $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
    $body .= "Content-Transfer-Encoding: 8bit" . $eol;
    $body .= $message . $eol;

    // attachment
    $body .= "--" . $separator . $eol;
    $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
    $body .= "Content-Transfer-Encoding: base64" . $eol;
    $body .= "Content-Disposition: attachment" . $eol;
    $body .= $content . $eol;
    $body .= "--" . $separator . "--";

    //SEND Mail
    if (mail($mailto, $subject, $body, $headers)) {
        echo "mail send ... OK"; // or use booleans here
    } else {
        echo "mail send ... ERROR!";
        print_r( error_get_last() );
    }

1
safa778 Messages postés 23 Date d'inscription mardi 15 mai 2018 Statut Membre Dernière intervention 27 mai 2018
25 mai 2018 à 09:43
mille merci :D
0