cfmail无法正常工作

Jac*_*ack 0 coldfusion cfmail sendgrid

我正在尝试使用以下脚本发送电子邮件,但它不起作用并抛出错误:

<cfmail to="user@mydomain.com" 
            from="user@mydomain.com" 
           <!---  subject="#sub#"   --->
            type="html" 
            server="smtp.sendgrid.net" 
            timeout="360" 
            username="un" 
            password="psw"  >

            <cfmailparam name="X-SMTPAPI" value="{\"category\":\"Cool Emails\"}">
            <cfoutput>
                Hello
            </cfoutput>
     </cfmail>
Run Code Online (Sandbox Code Playgroud)

错误是:找到无效的令牌\找到 <cfmailparam tag line

我已经尝试删除标签,但它仍然无法正常工作.

Mig*_*l-F 9

这不是你如何逃避CFML的引用.你应该能够加倍他们.像这样:

<cfmailparam name="X-SMTPAPI" value="{""category"":""Cool Emails""}">
Run Code Online (Sandbox Code Playgroud)

或者您可以使用单引号括起您的值而不是双引号.这将允许您在值中使用双引号.像这样:

<cfmailparam name='X-SMTPAPI' value='{"category":"Cool Emails"}'>
Run Code Online (Sandbox Code Playgroud)

此外,在您的示例中,您不需要在<cfoutput>标记内使用<cfmail>标记.