【问题标题】:cfmail is not formatting csscfmail 没有格式化 css
【发布时间】:2012-08-19 23:08:52
【问题描述】:

首先抱歉,我的知识有限,我刚刚开始在CF。

因此,当表单查询得到满足时,我尝试使用 cfmail 发送 html 电子邮件。

我遇到的问题是我嵌入到电子邮件头中的 css 要么抛出错误,要么根本没有格式化。请有人看看我的代码并告诉我哪里出错了。

顺便说一句,当我取出 css 中的 # 标签时,它似乎可以工作,但电子邮件发送时没有格式化!!!

    <cfmail to="customer email" from="xxxxxxx@gmail.com" subject="Your order at has been shipped" type="html">
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title</title>
<style type="text/css">
body {
    color: #000000;
    font-family: Arial, Helvetica, sans-serif;
}
body, td, th, input, textarea, select, a {
    font-size: 12px;
}
p {
    margin-top: 0px;
    margin-bottom: 20px;
}
a, a:visited, a b {
    color: #378DC1;
    text-decoration: underline;
    cursor: pointer;
}
a:hover {
    text-decoration: none;
}
a img {
    border: none;
}
#container {
    width: 680px;
}
#logo {
    margin-bottom: 20px;
}
table.list {
    border-collapse: collapse;
    width: 100%;
    border-top: 1px solid #DDDDDD;
    border-left: 1px solid #DDDDDD;
    margin-bottom: 20px;
}
table.list td {
    border-right: 1px solid #DDDDDD;
    border-bottom: 1px solid #DDDDDD;
}
table.list thead td {
    background-color: #EFEFEF;
    padding: 0px 5px;
}
table.list thead td a, .list thead td {
    text-decoration: none;
    color: #222222;
    font-weight: bold;
}
table.list tbody td a {
    text-decoration: underline;
}
table.list tbody td {
    vertical-align: top;
    padding: 0px 5px;
}
table.list .left {
    text-align: left;
    padding: 7px;
}
table.list .right {
    text-align: right;
    padding: 7px;
}
table.list .center {
    text-align: center;
    padding: 7px;
}
</style>
</head>
<body>
<div id="container">
  <p>Your Order has been Shipped</p>
  <table class="list">
    <thead>
      <tr>
        <td class="left" colspan="2">text_order_detail;</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="left"><b>text_order_id</b><br />
          <b>text_date_added</b><br />
          <b>text_payment_method</b><br />
          <b>text_shipping_method</b>
          </td>
        <td class="left"><b>text_email</b><br />
          <b>text_telephone</b><br />
          <b>text_ip<br /></td>
      </tr>
    </tbody>
  </table>
    <table class="list">
    <thead>
      <tr>
        <td class="left">text_instruction</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="left">comment</td>
      </tr>
    </tbody>
  </table>
  <table class="list">
    <thead>
      <tr>
        <td class="left">text_payment_address</td>
        <td class="left">text_shipping_address</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="left">payment_address</td>
        <td class="left">shipping_address</td>
      </tr>
    </tbody>
  </table>
  <table class="list">
    <thead>
      <tr>
        <td class="left">text_product</td>
        <td class="left">text_model</td>
        <td class="right">text_quantity</td>
        <td class="right">text_price</td>
        <td class="right">text_total</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="left">product
          <br />
          <small>option</small>
 </td>
        <td class="left">product['model']</td>
        <td class="right">product['quantity']</td>
        <td class="right">product['price']</td>
        <td class="right">product['total']</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="4" class="right"><b>total['title']</b></td>
        <td class="right">total['text']</td>
      </tr>
    </tfoot>
  </table>
  <p>text_footer</p>
  <p>text_powered</p>
</div>
</body>
</html>
    </cfmail>
        </cfif>

【问题讨论】:

  • 你想用##代替#
  • 您在哪些邮件客户端中遇到了这些问题?全部? MS Outlook、Mozilla Thunderbird、GoogleMail、...?
  • @Seybsen:我希望这根本不是邮件客户端。原始磅符号是 ColdFusion 中的可变标记,因此当您真正想要输出时需要转义它们(通过将它们加倍)。否则你会因为找不到变量而出错。

标签: css email coldfusion html-email cfmail


【解决方案1】:

有两个问题,第一个是您需要在 CSS 中使用 ## 而不是 #,否则 ColdFusion 会尝试将它们作为变量处理。第二个是您的页面底部有一个错误的&lt;/cfif&gt;,但这可能只是您复制和粘贴代码时的错误。

我使用 ## 而不是 # 测试了代码,并且在 CF 9.0.1 上正确发送了电子邮件

【讨论】:

  • 这里没有使用 ## 应该不是问题,因为 # 不在 CFOUTPUT 中,所以 ColdFusion 不会尝试处理它们。此外,如果这是问题所在,ColdFusion 会抛出错误,或者至少不会发送电子邮件。
  • 就像 OP 所说,它确实会引发错误。 cfmail 用作cfoutput,您不需要在cfmail 中使用cfoutput 标签
  • 哇 - 我真的不需要在醒来后立即阅读。由坏。继续伙计们……这里没什么可看的……
【解决方案2】:

您应该坚持 HTML 电子邮件的内联样式,而不是按照您的方式呈现样式。

例如

<td style="padding:10px;"></td>

【讨论】:

  • 我已转换为内联但仍然存在同样的问题:-(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2015-09-12
  • 2012-06-08
  • 2021-07-08
  • 1970-01-01
  • 2014-06-06
  • 1970-01-01
相关资源
最近更新 更多