【问题标题】:Email Div Content电子邮件分区内容
【发布时间】:2011-01-16 11:59:53
【问题描述】:

我正在尝试通过电子邮件发送 Div 的内容。我们有一个在线预订系统,用户可以选择他们想要的选项,然后提交表格。它会在下一页显示他们的信息以供他们打印。我还想要一份通过电子邮件发送给他们和我们的副本。

我喜欢 Jonathon Sampson 使用 ajax 脚本的电子邮件 div 的外观。但这对我不起作用。即使我给它一个写有一个单词的简单 Div,电子邮件总是返回说“null”。

我对 PHP 不太了解,以前使用过 CGI。 CGI 的问题是我无法设置电子邮件的样式。到目前为止,我在 PHP 中发现的一个问题是,虽然我可以将 HTML 添加到电子邮件中,但我无法决定要在哪里显示什么,并将来自人民表单的返回放在 HTML 电子邮件中的 DIV 中。

如果您查看以下页面,您将看到预订页面。此页面是初始表单提交返回其信息的地方。我希望以一种或另一种方式通过电子邮件将 DIV 标签“预订报价”内的所有内容发送给用户。附上代码 .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<div align="right" style="padding-top:10px;" id="booking_quote">
  <table width="775" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><table width="775" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="18" height="30" style="background:url(../../../IMAGES_A/Structure/Headers/blue-corner-piece-left-30px.gif); background-repeat:no-repeat;">&nbsp;</td>
          <td bgcolor="#263D51" style="border-left:1px solid #FFF; border-right:1px solid #FFF; padding-left:5px;"><div align="left" class="Text_normal" style="font-size:13px; color:#FFF;">Customer Records</div></td>
          <td width="18" height="30" style="background:url(../../../IMAGES_A/Structure/Headers/blue-corner-piece-right-30px.gif); background-repeat:no-repeat;">&nbsp;</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td style="padding-top:10px;"><div align="center">
        <table width="755" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="500"><div align="left">
              <table width="490" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="Corner-Box-WhiteGrey-TL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-T" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-TR" height="6" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td width="478"><table width="478" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="50%" valign="top"><div align="left" class="Text_normal">
                        <table width="230" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="77" valign="top" style="padding-right:12px;"><div align="right" style="color:#999;">Name</div></td>
                            <td width="153" valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_first-name"];?> <?php echo $_POST["CD_mid-initial"];?> <?php echo $_POST["CD_surname"];?></div></td>
                          </tr>
                          <tr>
                            <td valign="top" style="padding-right:12px;"><div align="right" style="color:#999;">Address</div></td>
                            <td valign="top" style="font-size:13px; color:#333;"><div align="left"> <?php echo $_POST["CD_address-L1"];?> <br />
                              <?php echo $_POST["CD_address-L2"];?> <br />
                              <?php echo $_POST["CD_address-settlement"];?><br />
                              <?php echo $_POST["CD_address-county"];?><br />
                              <?php echo $_POST["CD_address-post-code"];?><br />
                              <?php echo $_POST["CD_address-country"];?></div></td>
                          </tr>
                        </table>
                      </div></td>
                      <td width="50%" valign="top"><div align="right" class="Text_normal">
                        <table width="230" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="77" valign="top" style="padding-right:12px;"><div align="right" style="color:#999;">Date of Birth</div></td>
                            <td width="153" valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_DOB-day"];?>/<?php echo $_POST["CD_DOB-month"];?>/<?php echo $_POST["CD_DOB-year"];?></div></td>
                          </tr>
                          <tr>
                            <td valign="top" style="padding-right:12px;"><div align="right" style="color:#999;">Email</div></td>
                            <td valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_email"];?></div></td>
                          </tr>
                          <tr>
                            <td valign="top" style="padding-right:12px;"><div align="right" style="color:#999;">Telephone</div></td>
                            <td valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_telephone"];?></div></td>
                          </tr>
                        </table>
                      </div></td>
                    </tr>
                  </table></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
            </div></td>
            <td width="255" valign="top"><div align="right">
              <table width="250" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="Corner-Box-WhiteGrey-TL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-T" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-TR" height="6" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td><div align="center" class="Text_normal">
                    <table width="230" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top" style="padding-right:12px;"><div align="left" style="color:#999;">Highest Current Qualifiacation</div></td>
                      </tr>
                      <tr>
                        <td valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_experience-qualifications"];?></div></td>
                      </tr>
                      <tr>
                        <td width="230" valign="top" style="padding-right:12px; padding-top:5px;"><div align="left" style="color:#999;">Total Logged Dives to Date</div></td>
                      </tr>
                      <tr>
                        <td valign="top" style="font-size:13px; line-height:22px; color:#333;"><div align="left"> <?php echo $_POST["CD_experience-dives"];?></div></td>
                      </tr>
                    </table>
                  </div></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
            </div></td>
          </tr>
        </table>
      </div></td>
    </tr>
  </table>
  <br />
  <table width="775" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><table width="775" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="18" height="30" style="background:url(../../../IMAGES_A/Structure/Headers/blue-corner-piece-left-30px.gif); background-repeat:no-repeat;">&nbsp;</td>
          <td bgcolor="#263D51" style="border-left:1px solid #FFF; border-right:1px solid #FFF; padding-left:5px;"><div align="left" class="Text_normal" style="font-size:13px; color:#FFF;">Details</div></td>
          <td width="18" height="30" style="background:url(../../../IMAGES_A/Structure/Headers/blue-corner-piece-right-30px.gif); background-repeat:no-repeat;">&nbsp;</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td style="padding-top:10px;"><div align="center">
        <table width="755" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="575"><div align="left" class="Text_normal">
              <table width="565" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="Corner-Box-WhiteGrey-TL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-T" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-TR" height="6" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td width="553"><table width="553" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="428" valign="top" style="padding-bottom:3px; border-bottom:1px solid #CCC;"><div align="left" class="Text_Sub_Title"><?php echo $_POST["programme"];?></div></td>
                      <td width="125" valign="top" style="padding-bottom:3px; border-bottom:1px solid #CCC;"><div align="right" class="Text_Sub_Title" style="color:#333;">£<?php echo $_POST["Prog_total"];?></div></td>
                    </tr>
                    <tr>
                      <td colspan="2" valign="top" style="padding-top:3px;"><ul>
                        <div><?php echo $_POST["Prog_Sum_Sub_Open_Water_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Open_Water_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Refresh_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Refresh_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Advanced_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dives_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Safari_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Safari_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_2"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_3"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_4"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_5"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_6"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Dive_Specialities_01_7"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Discover_Safari_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Discover_Safari_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Equipment_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Accommodation_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Accommodation_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Accommodation_01_2"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Accommodation_01_3"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_PADI_Materials_Fees_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_PADI_Materials_Fees_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Transfers_01_0"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Transfers_01_1"];?></div>
                        <div><?php echo $_POST["Prog_Sum_Sub_Transfers_01_2"];?></div>
                      </ul></td>
                    </tr>
                  </table></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
              <br />
              <table width="565" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="Corner-Box-WhiteGrey-TL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-T" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-TR" height="6" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td width="553"><table width="553" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="428" valign="top"><div align="left" class="Text_Sub_Title"><?php echo $_POST["Store_Dive_The_Gap_Equipment_Package"];?></div></td>
                      <td width="125" valign="top"><div align="right" class="Text_Sub_Title" style="color:#333;"><?php echo $_POST["Store_Dive_The_Gap_Equipment_Package_total"];?></div></td>
                    </tr>
                    <tr>
                      <td colspan="2" valign="top" style="padding-top:3px;"><ul>
                        <div>
                          <div><?php echo $_POST["Store_Dive_The_Gap_Equipment_Package_details"];?></div>
                        </div>
                      </ul></td>
                    </tr>
                  </table></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
            </div></td>
            <td width="180" valign="top"><div align="right">
              <table width="170" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="6" colspan="3" valign="middle" class="Text_normal" style="background:url(../../../IMAGES_A/Structure/Headers/blue-Semicircle-170px.jpg); height:25px;"><div align="left" style="padding-left:20px; padding-top:4px; color:#FFF; font-size:13px; font-weight:bold;">Summary</div></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td width="158" bgcolor="#FFF"><div align="center" class="Text_normal" style="font-size:18px; color:#333; padding-top:12px; padding-bottom:12px; border-bottom:1px solid #CCC;">£<?php echo $_POST["Basket_Total"];?><span style="font-size:13px; color:#666; padding-left:4px;">incl. VAT</span></div>
                    <div align="center" class="Text_normal" style="font-size:12px; color:#666; padding-top:12px; padding-bottom:12px;"> <?php echo $_POST["Basket-Total-Duration-Text"];?><br />
                      <span style="font-size:10px; color:#666; padding-left:4px;">incl. arrival and departure day</span></div></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
              <br />
              <table width="170" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="6" colspan="3" valign="middle" class="Text_normal" style="background:url(../../../IMAGES_A/Structure/Headers/blue-Semicircle-170px.jpg); height:25px;"><div align="left" style="padding-left:20px; padding-top:4px; color:#FFF; font-size:13px; font-weight:bold;">Start Date</div></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-L" width="6"></td>
                  <td width="158" bgcolor="#FFF"><div align="left" class="Text_basic" style="padding-top:12px; padding-bottom:12px;">
                    <div align="center"><span style="font-size:14px; color:#666; padding-left:10px;" align="left" id="Prog-Start-Date-Text"></span><span class="Text_normal" style="font-size:12px; color:#666; padding-top:12px; padding-bottom:12px;"><?php echo $_POST["Prog_start-date"];?></span></div>
                  </div></td>
                  <td class="Corner-Box-WhiteGrey-R" width="6"></td>
                </tr>
                <tr>
                  <td class="Corner-Box-WhiteGrey-BL" height="6" width="6"></td>
                  <td class="Corner-Box-WhiteGrey-B" height="6"></td>
                  <td class="Corner-Box-WhiteGrey-BR" height="6" width="6"></td>
                </tr>
              </table>
            </div></td>
          </tr>
        </table>
      </div></td>
    </tr>
  </table>
  <br />
</div>
</body>
</html>

【问题讨论】:

  • 当我看到你的 HTML 时,我内心的符合网络标准的侏儒会痛苦地尖叫。
  • @Lior:除了虚假的&lt;ul&gt;,它实际上是符合标准的!当然,这绝对是令人痛苦的代码......天知道为什么它有嵌套五个深度的表,而一个带有几个 colspan 的表可以轻松完成。我怀疑它可能是由一个非常糟糕的所见即所得工具生成的。
  • 顺便说一句,它也充满了 HTML 注入错误,导致可能的 XSS 漏洞。需要更多htmlspecialchars。
  • @bobince:是的。有一段时间没有在 HTML 中看到 bgcolor="" 了。以为这些东西已经从世界上消失了。给上述问题所有者的一个建议:HTML 4.01 Strict 和验证器 :) 嘿,至少他没有使用间隔 gif,嗯?

标签: php javascript html forms


【解决方案1】:

听起来您在 PHP 设置中打开了 magic quotes。尝试将 $message 变量包装在 stripslashes 中。

【讨论】:

  • 我已经阅读了该做什么,并且当它直接出现在我的头上时。我该怎么做呢。我有一个参数str。我如何以及在哪里这样做。我不知道对不起。
【解决方案2】:

在 HTML 中,div 的 id 为“booking_quote”,而不是“booking-quote”。确保您在所有地方都使用“预订报价”。由于您没有附加 JavaScript 代码,因此很难看到发生了什么,但最简单的方法是

  1. 在您的页面上放置一个表单标签。给它一个“my-form”或其他的 id。
  2. 将事件附加到表单的提交方法
  3. 在方法中,取出div的内容,放入隐藏的表单域中

使用jQuery,会是这样的:

$('form#my-form').submit(function()
{
  $('input#my-hidden-field').val($('div#booking-quote').text())
});

【讨论】:

  • 很好,有点效果。非常感谢,现在,收到的电子邮件正在运行,但它没有附带任何图像或样式。所以我在 Div 中包含了 CSS 的 url,但它并没有帮助。 URLS 是完整的路由,所以这不是问题。我尝试包含整个页面,但问题似乎是系统性的。那里的图像不会枯萎。好像路线错了,但事实并非如此。有什么想法吗?
  • 这是一个不同的问题,完全取决于您正在查看电子邮件的电子邮件客户端。很多电子邮件客户端,尤其是基于 Web 的客户端,都会破坏图像路径。您是以 HTML 格式还是以文本电子邮件形式发送电子邮件?如果您将其作为 HTML 发送,请尝试将其作为文本发送以查看代码的外观。将其保存为文件,在浏览器中打开它,看看它是否正确。如果答案对您有用,那么将其标记为正确/投票如何?
  • 我正在使用 Apple Mail 客户端,类似于 Outlook。我得到它来显示电子邮件的原始来源。然后我复制了该来源并将其显示在网页中。它看起来像 HTML 代码,它显示了应该有表格的表格,但它在每个引号之前添加了 719 个反斜杠 '\'(即 height="6\"\ )当我手动取出这些电子邮件时按应有的方式显示。我将如何阻止它首先创建它们,任何想法。
  • 这里是 PHP 标头,如果您可以在那里发现问题:这里是 PHP 标头: $headers = "From: Dive The Gap Sales Team " 。 “\r\n”。 “内容类型:文本/html”。 "\r\n";邮件($to, $subject, $message, $headers);
猜你喜欢
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多