我试图使用基于标签的代码完成的简单示例:
<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/