【问题标题】:How do I write this complicated email template structure?如何编写这种复杂的电子邮件模板结构?
【发布时间】:2022-01-07 15:23:57
【问题描述】:

这是关于一个电子邮件模板,每个表格包含一个项目,右侧是图片,左侧是名称/品牌名称/尺寸等详细信息。 我尝试了一堆我在网上找到的不同解决方案,但我无法让结构对所有平台都具有足够的响应能力。 有关结构的任何资源都是有帮助的。我做了一张图片来描述结构的样子。

另一位用户指出,我可以展示我尝试过的最后一个模板以及我使用的一个效果不佳的资源。 https://codepen.io/Georgeslatina/pen/gOGzavj

<table role="presentation" cellpadding="0" cellspacing="0" width="580" style="margin: auto;height: 220px; table-layout: fixed; border: solid 1px #efefef; background-color: #fdfdfd; padding: 20px;margin-bottom:28px !important;direction:ltr !important">
  <tbody>
    <tr>
      <td colspan="60%">
        <table role="presentation" cellpadding="0" cellspacing="0" style="text-align: right; table-layout: fixed; width: 100%; height: 180px;">
          <tbody>
            <tr style="width: 100%;height:20%;">
              <td colspan="60%" style="">
                <div style="word-wrap: break-word;padding-right:12px;font-size:18px"> text2</div>
              </td>
              <td colspan="5%" style="">
                <div style="height: 20px; width: 1px;  background-color: black; margin: auto;">
                </div>
              </td>
              <td colspan="35%" style="">
                <div style="font-size:20px;word-wrap: break-word;padding-right:22%"> text1</div>
              </td>
            </tr>
            <tr>
              <td colspan="44%" style="">
                <div style="padding-right:10px">
                  <span> ₪100  </span>
                  <span style="padding-left:8px"> מחיר</span>
                </div>
              </td>
              <td colspan="2%" style="">
                <div style="height: 20px; width: 1px;  background-color: #e6e6e6; margin: auto;">
                </div>
              </td>
              <td colspan="24%" style="">
                <div style="padding-right:20%">
                  <span style="padding-left:8px">L </span>
                  <span>מידה</span>
                </div>
              </td>
              <td colspan="2%" style="">
                <div style="height: 20px; width: 1px;  background-color: #e6e6e6; margin: auto;">
                </div>
              </td>
              <td colspan="13%" style="padding-right:8px">
                <div style="border-radius:50%; width: 11px; height: 11px; border: 2px solid black; margin-left:65%">
                  <div style="width: 9px; height: 9px;border-radius:50%; margin:auto; margin-top:1px"></div>
                </div>
              </td>
              <td colspan="11%">
                <div style="float:left">צבע</div>
              </td>
            </tr>

            <tr>
              <td colspan="100%" style="padding-right:30px;height:30px">
                <div style="text-align:right">
                  <span>
                                reason 
                                </span>
                  <span style="text-align:right;font-family:NarkisBlockMF;font-size:18px;font-weight: 550;font-stretch: normal;font-style: normal;line-height: 1.28;letter-spacing: normal;color: #000;">  :סיבת החזרה</span>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="25%" style="position: relative">
        <div style="display:block;width:135px; height:180px;text-align: center; font-size: 0; background:url('https://i.natgeofe.com/n/46b07b5e-1264-42e1-ae4b-8a021226e2d0/domestic-cat_thumb_square.jpg') no-repeat center; background-size: cover">
        </div>
        <div style="
                position:absolute;
                z-index: 1;
                bottom:0;
                width: 135px;
                height: 24px;
                opacity: 0.8;
                font-family:NarkisBlockMF;
                font-size:17px;
                background-color: #000;
                color: white;
                text-align: center;
                line-height: 24px;">
          פריט החזרה
        </div>
      </td>
    </tr>
  </tbody>
</table>

示例中的条件 VML 在我的测试中不起作用。 https://stackoverflow.design/email/templates/short-transactional/

【问题讨论】:

  • 尝试在 CSS 中探索 flex/grid。您需要两个 div/部分,一个在左侧,另一个在右侧。
  • 您好,这个网站是为帮助其他开发者的开发者准备的。为了让我们能够为您提供帮助,我们需要看到您的努力。你试过什么了?请分享您的代码、您的尝试、试验以及您正在努力解决的问题。这不是“we-are-doing-your-work.com”网站
  • @kiner_shah 嘿,大多数电子邮件客户端不支持 Flex/grid。
  • @toesslab 嘿,对不起,如果我似乎在要求整件事。自从我尝试了在 google 上找到的前几页后,我一直在寻求任何有用的资源,任何对所有客户都有响应的资源,但它们没有按预期工作。
  • @toesslab 这是我做的最后一个模板,它与 Outlook/mail 相去甚远。 codepen.io/Georgeslatina/pen/gOGzavj 如果我要引用一个我用过但对我没有用的来源,那就是 stackoverflow.design/email/templates/short-transactional

标签: html css email html-table html-email


【解决方案1】:

这是一种实现图像中所拥有的混合方法。我的代码不依赖于媒体查询,但我添加了一个类以使我的块在移动设备中具有 100% 的宽度。如果将其删除,则具有 text3、text2 和 text1 的行将在其达到较小的屏幕尺寸时自行开始堆叠。

我没有放入任何管道/分隔符,因为它们可以在您添加内容时放置。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Untitled Document</title>
<style type="text/css">
/*not smart phones*/
@media only screen and (max-width:480px) {
    .fullWidth{width:100% !important;max-width:100% !important;}
}
</style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td><!--[if (gte mso 9)|(IE)]>
<table width="700" align="center" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td align="left" valign="top" width="700">
<![endif]--> 
            
            <!-- start 700 pixel container -->
            
            <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="fullWidth" style="max-width:700px;">
                <tbody>
                    <tr>
                        <td align="center" valign="top" style="text-align: center; vertical-align: top; font-size: 0px; padding: 0px;"><!--[if (gte mso 9)|(IE)]>
<table width="700" align="center" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td align="left" valign="top" width="350">
<![endif]-->
                            
                            <div style="max-width: 349px; width:100%; display: inline-block; vertical-align: top;">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tbody>
                                        <tr>
                                            <td align="center" valign="top" style="text-align: center; vertical-align: top; font-size: 0px; padding: 0px;"><!--[if (gte mso 9)|(IE)]>
                                            <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
                                                <tr>
                                                    <td align="left" valign="top" width="175">
                                            <![endif]-->
                                                
                                                <div style="max-width: 174px; width:100%; display: inline-block; vertical-align: top;">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text1</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                                </td><td align="left" valign="top" width="175">
                                                <![endif]-->
                                                
                                                <div style="max-width: 174px; width:100%; display: inline-block; vertical-align: top;">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text2</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                                    </td>
                                                </tr>
                                            </table>
                                            <![endif]--></td>
                                        </tr>
                                        <tr>
                                            <td align="center" valign="top" style="text-align: center; vertical-align: top; font-size: 0px; padding: 0px;"><!--[if (gte mso 9)|(IE)]>
                                            <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
                                                <tr>
                                                    <td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text3</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                            </td><td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text2</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                            </td><td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text1</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                                    </td>
                                                </tr>
                                            </table>
                                            <![endif]--></td>
                                        </tr>
                                        <tr>
                                            <td align="center" valign="top" style="text-align: center; vertical-align: top; font-size: 0px; padding: 0px;"><!--[if (gte mso 9)|(IE)]>
                                            <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
                                                <tr>
                                                    <td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;"></td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                            </td><td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text2</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                            </td><td align="left" valign="top" width="116">
                                            <![endif]-->
                                                
                                                <div style="max-width: 116px; width:100%; display: inline-block; vertical-align: top;" class="fullWidth">
                                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text1</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                                
                                                <!--[if (gte mso 9)|(IE)]>
                                                    </td>
                                                </tr>
                                            </table>
                                            <![endif]--></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            
                            <!--[if (gte mso 9)|(IE)]>
</td><td align="left" valign="top" width="350">
<![endif]-->
                            
                            <div style="max-width: 349px; width:100%; display: inline-block; vertical-align: top;">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tbody>
                                        <tr>
                                            <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">image</td>
                                        </tr>
                                        <tr>
                                            <td style="font-family: Helvetica, Arial, sans-serif;font-size:20px;">text</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            
                            <!--[if (gte mso 9)|(IE)]>
        </td>
    </tr>
</table>
<![endif]--></td>
                    </tr>
                </tbody>
            </table>
            
            <!-- start 700 pixel container --> 
            
            <!--[if (gte mso 9)|(IE)]>
        </td>
    </tr>
</table>
<![endif]--></td>
    </tr>
</table>
</body>
</html>

【讨论】:

    【解决方案2】:

    不要将布局设置在单个表格中,将它们分成两个表格。内容表和图像表。

    <style>
      @media screen and (max-width: 600px) {
        .module-wrapper, .grid{
          width: 100% !important;
        }
        .grid{
          float: none !important;
        }
      }
    </style>
    
    <table class="module-wrapper" cellpadding="0" cellspacing="0" border="0" width="580" align="center">
      <tr>
        <td>
          <!--[if mso]><table cellpadding="0" cellspacing="0" border="0" width="100%" dir="rtl"><tr><td valign="top" dir="ltr"><![endif]-->
          <table class="grid" cellpadding="0" cellspacing="0" border="0" width="135" align="right">
            <tr>
                <td align="center" style="position: relative">
                  <table cellpadding="0" cellspacing="0" border="0">
                    <tr>
                      <td>
                        <div style="display:block;width:135px; height:180px;text-align: center; font-size: 0; background:url('https://i.natgeofe.com/n/46b07b5e-1264-42e1-ae4b-8a021226e2d0/domestic-cat_thumb_square.jpg') no-repeat center; background-size: cover">
                        </div>
                        <div style="
                                position:absolute;
                                z-index: 1;
                                bottom:0;
                                width: 135px;
                                height: 24px;
                                opacity: 0.8;
                                font-family:NarkisBlockMF;
                                font-size:17px;
                                background-color: #000;
                                color: white;
                                text-align: center;
                                line-height: 24px;">
                          פריט החזרה
                        </div>
                      </td>
                    </tr>
                  </table>
                  
                </td>
              </tr>
          </table><!-- #end image table -->
          <!--[if mso]></td><td valign="top" dir="ltr"><![endif]-->
          <table class="grid" role="presentation" cellpadding="0" cellspacing="0" width="445" align="left">
              <tr>
                <td colspan="60%">
                  <table role="presentation" cellpadding="0" cellspacing="0"
                    style="text-align: right; table-layout: fixed; width: 100%; height: 180px;">
                    <tbody>
                      <tr style="width: 100%;height:20%;">
                        <td colspan="60%" style="">
                          <div style="word-wrap: break-word;padding-right:12px;font-size:18px"> text2</div>
                        </td>
                        <td colspan="5%" style="">
                          <div style="height: 20px; width: 1px;  background-color: black; margin: auto;">
                          </div>
                        </td>
                        <td colspan="35%" style="">
                          <div style="font-size:20px;word-wrap: break-word;padding-right:22%"> text1</div>
                        </td>
                      </tr>
                      <tr>
                        <td colspan="44%" style="">
                          <div style="padding-right:10px">
                            <span> ₪100 </span>
                            <span style="padding-left:8px"> מחיר</span>
                          </div>
                        </td>
                        <td colspan="2%" style="">
                          <div style="height: 20px; width: 1px;  background-color: #e6e6e6; margin: auto;">
                          </div>
                        </td>
                        <td colspan="24%" style="">
                          <div style="padding-right:20%">
                            <span style="padding-left:8px">L </span>
                            <span>מידה</span>
                          </div>
                        </td>
                        <td colspan="2%" style="">
                          <div style="height: 20px; width: 1px;  background-color: #e6e6e6; margin: auto;">
                          </div>
                        </td>
                        <td colspan="13%" style="padding-right:8px">
                          <div style="border-radius:50%; width: 11px; height: 11px; border: 2px solid black; margin-left:65%">
                            <div style="width: 9px; height: 9px;border-radius:50%; margin:auto; margin-top:1px"></div>
                          </div>
                        </td>
                        <td colspan="11%">
                          <div style="float:left">צבע</div>
                        </td>
                      </tr>
        
                      <tr>
                        <td colspan="100%" style="padding-right:30px;height:30px">
                          <div style="text-align:right">
                            <span>
                              reason
                            </span>
                            <span
                              style="text-align:right;font-family:NarkisBlockMF;font-size:18px;font-weight: 550;font-stretch: normal;font-style: normal;line-height: 1.28;letter-spacing: normal;color: #000;">
                              :סיבת החזרה</span>
                          </div>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
          </table><!-- #end content table -->
          <!--[if mso]></td></tr></table><![endif]-->
        </td>
      </tr>
    </table><!-- #end module-wrapper -->

    然后使用媒体查询让您的表格响应式

    如果您不想使用媒体查询,请尝试使用本文中的方法 https://webdesign.tutsplus.com/tutorials/creating-a-future-proof-responsive-email-without-media-queries--cms-23919

    【讨论】:

      【解决方案3】:

      使用 php 就是这么简单

      $to = 'reciver';
      
      $subject = 'subt';
      
      $headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
      $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
      $headers .= "CC: xyz@gmail.com\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
      
      $message = '<p><strong>This is strong text</strong> while this is not.</p>'; // hear will be your ful structure in html in message variable.
      //Then
      
      
      mail($to, $subject, $message, $headers);
      

      请确认您已经使用过这条线路

      $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
      
      

      【讨论】:

      • 嘿,如果我最初的帖子不清楚,很抱歉,但我正在寻找模板内 html/css 的建议/资源。
      • 你只想要结构的 html 代码,对吗?
      • 只是简单的 HTML 和 css
      • 希望我把最初的帖子写得更清楚一点
      【解决方案4】:

      我尝试为此使用 CSS 网格

      #parent-container {
        border: 0.2rem solid black;
        padding: 1em;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        place-content: center;
      }
      
      #parent-container img {
        width: 100%;
        height: auto;
        border-radius: 0.3rem;
      }
      
      .first-container {
        height: 100%;
        display: grid;
        grid-auto-rows: 1fr;
      }
      
      .first-container div:nth-child(1) {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        place-items: center;
      }
      
      .first-container div:nth-child(2) {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        place-items: center;
      }
      
      .first-container div:nth-child(3) {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        place-items: center;
      }
      
      .first-container div>div:not(:last-child) {
        border-right: 0.2rem solid black;
      }
      
      .first-container div {
        display: grid;
        gap: 0.5rem;
      }
      
      .second-container {
        display: grid;
        place-items: center;
        border: 0.2rem solid black;
        padding: 0.5em;
      }
      <!DOCTYPE html>
      <html lang="en">
      
      <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="style.css">
      </head>
      
      <body>
        <div id="parent-container">
          <!-- first container-child -->
          <div class="first-container">
            <div>
              <div>text1</div>
              <div>text2</div>
            </div>
            <div>
              <div>text3</div>
              <div>text2</div>
              <div>text1</div>
            </div>
            <div>
              <div></div>
              <div>text2</div>
              <div>text1</div>
            </div>
          </div>
          <!-- second container-child -->
          <div class="second-container">
            <img src="https://avatars.githubusercontent.com/u/87947051?v=4" alt="">
            <div>text</div>
          </div>
        </div>
      </body>
      
      </html>

      【讨论】:

      • 嘿,感谢您的努力,但正如 campaignmonitor.com/css 网格上所见,大多数电子邮件客户端不支持许多其他 css,这就是我在使用模板时遇到问题的原因。跨度>
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2020-02-25
      • 2017-04-29
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 2016-10-28
      相关资源
      最近更新 更多