ColdFusion cfmail special characters in subject line

柔情痞子 提交于 2019-11-30 05:26:58

问题


Special characters in the subject line of the mail getting converted in to question marks or boxes.

I have tried to wrap the dynamic string of the subject line in URLEncodedFormat , however ended up in vain.

<cfset strSubject= URLEncodedFormat(s)>
<cfmail 
  from="xxxxx@xx.com" 
  to="yyyyyyy@yyy.com" 
  subject="#strSubject#"         
  type="html"
>
  #testText#
</cfmail>

回答1:


Assuming the special characters are unicode charactes, you will have to encode the string to a base64 format and use that in the subject line. Like this,

<cfset strSubject="Demande d’chantillons supplémentaires">
<cfset strSubject=ToBase64(strSubject, "utf-8")>

<cfmail from="test@test.com" to="test@test.com" subject="=?utf-8?B?#strSubject#?=" type="html">
    #testText#
</cfmail>

The subject line must be in the format =?<charset>?<encoding>?<encoded text>?=

The ? and = are required.

MIME - Encoded Word

"charset" may be any character set registered with IANA. Typically it would be the same charset as the message body.

"encoding" can be either "Q" denoting Q-encoding that is similar to the quoted-printable encoding, or "B" denoting base64 encoding.

"encoded text" is the Q-encoded or base64-encoded text.




回答2:


Also: add charset="utf-8" to the cfmail tag. If you are using utf-8 in the subject, you will probably also use it in the body.



来源:https://stackoverflow.com/questions/9374948/coldfusion-cfmail-special-characters-in-subject-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!