How to use special characters in recipients name when using PHP's mail function

后端 未结 2 489
迷失自我
迷失自我 2020-11-27 22:01

How can I send an email formatted as \"Name \" to:

ŠŒŽœžŸ¥µÀÁÃÄÅÆÇÉÊËÍÎÏÐÒÓÕÖØÙÜÝßàáâåæçèéëìíîïðñóôõöøùûýÿ 

        
相关标签:
2条回答
  • 2020-11-27 22:21

    RFC-821 (2821) tells us, that all and any 8bit-data in headers field must be encoded. Base64 or QuotedPrintable, as you want and can. Most e-mail readers automatically decode encoded strings

    0 讨论(0)
  • 2020-11-27 22:27

    mb_encode_mimeheader should do it, just as shown in the example:

    mb_internal_encoding('UTF-8');
    
    $name  = '山本';
    $email = 'yamamoto@example.com';
    $addr  = mb_encode_mimeheader($name, 'UTF-8', 'Q') . " <$email>";
    

    For better compatibility you should set the header Mime-Version: 1.0 so all mail clients understand you're using MIME encoding.

    The final email headers should look like this:

    To: =?UTF-8?Q?=E5=B0=81=E3=83=90=E3=83=BC?= <yamamoto@example.com>
    Subject: =?UTF-8?Q?=E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF?=
    Mime-Version: 1.0
    

    Renders as:

    To: 山本 <yamamoto@example.com>
    Subject: こんにちは
    

    Related: https://stackoverflow.com/a/13569317/476

    0 讨论(0)
提交回复
热议问题