Coldfusion 2016 如何在使用 cfscript mail() 时包含模板?

标签 coldfusion coldfusion-10 coldfusion-2016

我试图使用基于标签的代码完成的简单示例:

<cfmail
   to="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7c4d8dad2d8d9d2f7cf99d4d8da" rel="noreferrer noopener nofollow">[email protected]</a>"
   from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85f6eae8e0eaebe0c5fcabe6eae8" rel="noreferrer noopener nofollow">[email protected]</a>"
   subject="howdy"
   type="html">
      <cfinclude template="path/to/emailtemplates/sometemplate.htm"/>
</cfmail>

我已经使用 cfscript 尝试了各种解决方案,但遇到了障碍。我以为这可以做到,但可惜没有。

savecontent variable="mailBody" {
  include "path/to/emailtemplates/sometemplate.htm";
};
mail = new mail();
mail.setTo( "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02716d6f676d6c67427a2c616d6f" rel="noreferrer noopener nofollow">[email protected]</a>" );
mail.setFrom( "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a7bbb9b1bbbab194adfab7bbb9" rel="noreferrer noopener nofollow">[email protected]</a>" );
mail.setSubject( "howdy!" );
mail.setType( "HTML" );
mail.setBody( mailBody );
mail.send();

我们不会发送多部分电子邮件 - 只是 HTML。有没有办法在脚本中做到这一点?

最佳答案

问题是,在 cfinlcude 中,您将无法包含 HTML 文件。看起来您将需要 FileRead() 函数的帮助而不是包含。

mailBody=FileRead('absolute/path/to/emailtemplates/sometemplate.htm' [, charsetIfNeeded]);

要使 FileRead 正常工作,您应该提供服务器上磁盘上或内存中文本文件的绝对路径。

关于Coldfusion 2016 如何在使用 cfscript mail() 时包含模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50687198/

相关文章:

oracle - cfqueryparam 中 Oracle 的 Number(*,0) 数据类型使用哪种 cfsqltype?

coldfusion - 如何在 QueryExecute sql 语句中正确转义冒号?

iis - 如何从状态代码 500 页面中删除内部服务器错误短语?

php - curl 到 cfhttp 翻译

coldfusion - 我如何使用 AngularJS 和 serializeJSON cfquery

coldfusion - CF 从 7 迁移到 8,CF8 由于表锁而崩溃,但其他服务器仍在 7 上运行良好!

coldfusion - 如何在 ColdFusion 8 中使 ARGUMENTS 成为可选?

coldfusion - Application.cfc : this. debugipaddress 和this.debuggingIPAddresses,有什么区别?

coldfusion - 在查询的ColdFusion查询中使用count()函数

coldfusion - 使用 ColdFusion (2016) 遍历电子表格数据并对输出进行分组