ColdFusion如果语句在<cfmail>中导致间距

Ste*_*her 1 html email coldfusion

我正在通过<cfmail>ColdFusion 发送一封电子邮件,我遇到了一个问题,即我的电子邮件中出现这些换行符,尽管我的代码没有那么多换行符.

我的同事告诉我,多行if语句会导致这种情况,所以我将它们作为单行语句,但我的电子邮件中仍然存在突破性的行!

<cfmail ... >
    <strong><u>Event Details: </u></strong><br />
    <strong>What:</strong><cfif itemsforForm.normalTicket EQ true>Brunch</cfif><br />
    <strong>When:</strong> Sunday, August 17th, 2014<br />
    <cfif(itemsForForm.sponsor GT 0)>11:00am-2:00pm<br /></cfif> <!--- these cause the line breaks --->
    <cfif itemsforForm.normalTicket EQ true>11:30am-1:00pm<br /></cfif>
    <cfif itemsForForm.vipTicket EQ true>11:30am-2:00pm</cfif>
</cfmail>
Run Code Online (Sandbox Code Playgroud)

对于<cfif>我的电子邮件中的每一个,输出中都会出现换行符.为什么会这样?

Ada*_*ron 7

仔细查看您的代码:

<cfmail ... >
    <strong><u>Event Details: </u></strong><br />
    <strong>What:</strong><cfif itemsforForm.normalTicket EQ true>Brunch</cfif><br />
    <strong>When:</strong> Sunday, August 17th, 2014<br />
    <cfif(itemsForForm.sponsor GT 0)>11:00am-2:00pm<br /></cfif> <!--- these cause the line breaks --->
    <cfif itemsforForm.normalTicket EQ true>11:30am-1:00pm<br /></cfif>
    <cfif itemsForForm.vipTicket EQ true>11:30am-2:00pm</cfif>
</cfmail>
Run Code Online (Sandbox Code Playgroud)

在每行代码的末尾都是换行符.这就是为什么它们不是一个连续的代码行.如果你的if条件是假的,你将无法获得该<cfif>块的内容,但你仍然会在之后得到换行符</cfif>

要解决此问题,请启用cfoutput-only模式(with <cfsettings>),然后在带有<cfoutput>标记的邮件消息中包含您想要的内容.

或者使用CFScript而不是标签.它不会发出任何你不告诉它的东西.