Unicode entities in email subject

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laangen_LU

    #1

    Unicode entities in email subject

    Dear Group,

    my first post to this group, so if I'm on the wrong group, my
    apologies.

    I'm trying to send out an email in Chinese lanuage using the mail()
    function in PHP.

    Subject and mailbody are stored as Unicode entities (eg. 註)

    The mail body renders perfectly in all tested emailclients if the mail
    is sent as html.

    Only the subject displays the entities but does not render the Chinese
    chars.

    Any ideas on how to get the mail sent with the subject displaying
    correctly?

    Thank you in advance for any clue available on this topic.

    Patrick Huss

  • Andy Hassall

    #2
    Re: Unicode entities in email subject

    On 8 Dec 2006 07:29:39 -0800, "Laangen_LU " <patrick.huss@g mail.comwrote:
    >my first post to this group, so if I'm on the wrong group, my
    >apologies.
    >
    >I'm trying to send out an email in Chinese lanuage using the mail()
    >function in PHP.
    >
    >Subject and mailbody are stored as Unicode entities (eg. 註)
    >
    >The mail body renders perfectly in all tested emailclients if the mail
    >is sent as html.
    >
    >Only the subject displays the entities but does not render the Chinese
    >chars.
    >
    >Any ideas on how to get the mail sent with the subject displaying
    >correctly?
    >
    >Thank you in advance for any clue available on this topic.
    Encoding in headers of mail messages uses a different scheme to HTML. I
    believe the specification you want is RFC 1342 "Representa tion of Non-ASCII
    Text in Internet Message Headers" (http://rfc.net/rfc1342.html)

    You'll likely have to decode the subject's HTML entity references and recode
    them as above.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Umberto Salsi

      #3
      Re: Unicode entities in email subject

      "Laangen_LU " <patrick.huss@g mail.comwrote:
      my first post to this group, so if I'm on the wrong group, my
      apologies.
      >
      I'm trying to send out an email in Chinese lanuage using the mail()
      function in PHP.
      >
      Subject and mailbody are stored as Unicode entities (eg. 註)
      >
      The mail body renders perfectly in all tested emailclients if the mail
      is sent as html.
      >
      Only the subject displays the entities but does not render the Chinese
      chars.
      >
      Any ideas on how to get the mail sent with the subject displaying
      correctly?
      >
      Thank you in advance for any clue available on this topic.
      The "Subject" field can be encoded as MIME header (see RFC 2045-2048).
      For example, given the subject $subj encoded as a UTF-8 string,
      a possible encoding might be

      define("ENCODIN G", "UTF-8");

      $header = "Subject: =?" . ENCODING . "?B?" . base64_encode($ subj) . "?=\r\n";

      Note that the RFC 2047 sets a limit to the maximum lenght of the resulting
      string. Beyond that limit the string must be splitted somewere. However,
      the email clients I tested are able to accept a string of any length,
      so this is a problem you may ignore as a first step of the implementation.

      And note that this encoding has nothing to do with the Content-Type
      field or the body of the message.

      Obviously, your "Unicode entities" must be converted to regular UTF-8
      characters before the Base64 encoding be applied.

      Regards,
      ___
      /_|_\ Umberto Salsi
      \/_\/ www.icosaedro.it

      Comment

      • Laangen_LU

        #4
        Re: Unicode entities in email subject

        Thank you very much Umberto and Andy for your help.

        The script is working now and Chinese emails arrive with nice rendrered
        Chinese subjects lines.

        I found the following function written by ronen to convert Unicode
        entities back to a unicode string:



        Using this before doing the base64 encoding does the trick.

        Cheers,
        Patrick Huss


        Umberto Salsi schrieb:
        "Laangen_LU " <patrick.huss@g mail.comwrote:
        >
        my first post to this group, so if I'm on the wrong group, my
        apologies.

        I'm trying to send out an email in Chinese lanuage using the mail()
        function in PHP.

        Subject and mailbody are stored as Unicode entities (eg. 註)

        The mail body renders perfectly in all tested emailclients if the mail
        is sent as html.

        Only the subject displays the entities but does not render the Chinese
        chars.

        Any ideas on how to get the mail sent with the subject displaying
        correctly?

        Thank you in advance for any clue available on this topic.
        >
        The "Subject" field can be encoded as MIME header (see RFC 2045-2048).
        For example, given the subject $subj encoded as a UTF-8 string,
        a possible encoding might be
        >
        define("ENCODIN G", "UTF-8");
        >
        $header = "Subject: =?" . ENCODING . "?B?" . base64_encode($ subj) . "?=\r\n";
        >
        Note that the RFC 2047 sets a limit to the maximum lenght of the resulting
        string. Beyond that limit the string must be splitted somewere. However,
        the email clients I tested are able to accept a string of any length,
        so this is a problem you may ignore as a first step of the implementation.
        >
        And note that this encoding has nothing to do with the Content-Type
        field or the body of the message.
        >
        Obviously, your "Unicode entities" must be converted to regular UTF-8
        characters before the Base64 encoding be applied.
        >
        Regards,
        ___
        /_|_\ Umberto Salsi
        \/_\/ www.icosaedro.it

        Comment

        Working...