SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    accented characters [from] field mail

    I've made a flash mailform. This communicates with below script to send the mail. Which works ok. I've used utf8_decode to also make it send accented characters like ë á é ü etc. In the message field this works ok. All accented characters display. In the 'from' field however, these accented characters still appear funny. Like when it should display 'René' in the from-field, it displays 'renX' in the from-field. In the message field is still display's René.

    What do I have to do to also make it work in the from-field?

    PHP Code:
    <?php
    // initialize variables for To and Subject fields
    $to 'info@test.nl';
    $subject 'Een vraag';
    $from stripslashes(utf8_decode($_POST['from']));
    $email stripslashes(utf8_decode($_POST['email']));
    $comments stripslashes(utf8_decode($_POST['comments']));

    // build message body from variables received in the POST array
    $message 'Van: ' $from "\n\n";
    $message .= 'Email: '$email ."\n\n";
    $message .= 'Bericht: '$comments;

    //convert flash line breaks
    $message ereg_replace("\r""\n"$message);

    // add additional email headers for more user-friendly reply
    $additionalHeaders "MIME-Version: 1.0\r\n";
    $additionalHeaders .= "Content-type: text/html; charset= ISO 8859-1\r\n"
    $additionalHeaders .= "From: " $from ." <" $email ">\r\n"
    $additionalHeaders .= "Reply-To: " $email;


    // send email message
    $OK mail($to$subject$message$additionalHeaders);
    // let Flash know what the result was
    if ($OK) {
      echo 
    'sent=OK';
      }
      else {
      echo 
    'sent=failed&reason='urlencode('Er is een probleem met de server. Probeer het later nog eens.');
      }
    ?>

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Character sets really isn't something I'm strong on, however it may have something to do with the following line:
    PHP Code:
    $additionalHeaders .= "Content-type: text/html; charset= ISO 8859-1\r\n"
    You're telling the email client that the charset is Latin1 (ISO 8859-1), yet you are sending it as UTF-8.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't think so? I had to use utf8_decode on the output from flash cause flash sends it's output in utf8. Otherwise accented characters from the flash form would turn into strange codes. So that turns the utf8 output from flash into ISO 8859-1 for php. And in the message field of the email, these accented characters appear ok now. Accept in the from field of the email. Ren&#233; now turns into RenXX

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    Macomb, MI USA
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would suggest using the PHPMailer class as this will save you a lot of headaches:
    http://phpmailer.worxware.com/

    Once you get the class configured and running, it's pretty trivial to get the character set and mime types you need.

    -Bing
    inClick Ad Server - Start Your Own Performance Based Ad Network
    Key Features | Download inClick Now | Free Ad Server Hosting Offer

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Content-Type field only applies to the body of the message.

    For the headers, you have to use MIME encoded-word:
    http://en.wikipedia.org/wiki/MIME#Encoded-Word

    There are quite a few PHP classes to handle emailing, such as PHPMailer or Swift Mailer, that will do all of this for you.

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that mean I should also encode the mail fields like from: cc: bcc: by using mb_encode_mimeheader?

    So like this?
    $additionalHeaders .= "From: " . mb_encode_mimeheader($from, "iso-8859-1", "Q") ." <" . $email . ">\r\n";

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes.

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried putting it all in utf-8 now and used this mime encoding on the from field to turn that into utf-8 also.

    However, when I send a mail as 'René', in the From field of the email I receive it says rené <test@mail.com>.

    In the message text it reads:

    From: rené

    Email: test@mail.com

    Message: rené is writing this email.

    This is while the email is viewed in html mode. When I switch to plain text mode, the message text reads 'René' again, but the From field still ' rené'.

    How can I fix it that both the From field as the Message field in html mode both display accented characters?

    PHP Code:
    <?php
    // initialize variables for To and Subject fields
    $to 'info@testmail.nl';
    $subject 'Een testmail';
    $from $_POST["from"];
    $email $_POST["email"];
    $comments $_POST["comments"];

    // build message body from variables received in the POST array
    $message "Van: $from \n\n";
    $message .= "Email: $email \n\n";
    $message .= "Bericht: $comments";
    $message stripslashes($message);

    //convert flash line breaks
    $messagestr_replace("\r""\n"$message);
    $message=nl2br($message);

    // add additional email headers for more user-friendly reply
    $additionalHeaders "MIME-Version: 1.0\r\n";
    $additionalHeaders .= "Content-type: text/html; charset=utf-8\r\n";
    $additionalHeaders .= "From: " mb_encode_mimeheader($from"utf-8""Q") ." <" $email ">\r\n";
    $additionalHeaders .= "Reply-To: ".$email."\r\n";



    // send email message
    $OK mail($to$subject$message$additionalHeaders);
    // let Flash know what the result was
    if ($OK) {
      echo 
    'sent=OK';
      }
      else {
      echo 
    'sent=failed&reason='urlencode('Er is een probleem met de server. Probeer het later nog eens.');
      }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •