Re: Accented characters appearing as question marks in a unicoded mail

From: Date: Fri, 18 Oct 2002 07:34:47 +0000
Subject: Re: Accented characters appearing as question marks in a unicoded mail
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120467@lists.php.net to get a copy of this message
Hello, On 10/17/2002 07:26 PM, Nicolas wrote:
Well, here it is, I've set up a code for sending a form that goes a little something like this: <?php
    if($_POST['okList'] == 1) {
        $fp = fopen("log/emailLog.txt", "a");
        $wp = fwrite($fp, $_POST['Email'] . "\r\n");       }
        $from = $_POST['Name'] . "<" . $_POST['Email'] . ">";
    $to = "dorobo88@digitalmilitia.net";
    $subject = "Demande de renseignement";
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "From: " . $from . "\r\n";
           $tmpBody = "Nom: " . $_POST['Name'] . "\n";
    $tmpBody .= "Entreprise: " . $_POST['Ent'] . "\n";
    $tmpBody .= "Adresse: " . $_POST['Address'] . "\n";
    $tmpBody .= "Ville: " . $_POST['City'] . "\n";
    $tmpBody .= "Province: " . $_POST['Province'] . "\n";
    $tmpBody .= "Pays: " . $_POST['Country'] . "\n";
    $tmpBody .= "Code Postal/Zip: " . $_POST['Zip'] . "\n";
    $tmpBody .= "Message:\n" . $_POST['Message'] . "\n";
    $tmpArr = explode(',', urldecode($_POST['Attach']));
    $tmpBody .= "Catalogue(s) demandé(s):\n";
    foreach($tmpArr as $cat) {
        $tmpBody .= $cat . "\n";
    }
    $body = nl2br($tmpBody);
        $ok_mail = mail($to, $subject, $body, $headers);
        echo($ok_mail . $body);   ?>
everything works fine EXCEPT the "é" from "demandé" that is displayed as a "?" in the output mail.
That is because you specified utf-8 encoding charset instead of iso-8859-1 . You also need to use quoted printable to encode the text message body to avoid further problems. You may want to try this class that encodes the accented characters and other 8 bit charactares properly even in message headers: http://www.phpclasses.org/mimemessage -- Regards, Manuel Lemos

« previous php.general (#120467) next »