通过 PHP 发送 HTML 邮件 - 奇怪的渲染

发布于 2024-09-29 02:05:44 字数 1029 浏览 0 评论 0原文

我有一个简单的表:

<table cellpadding="0" cellspacing="0" style="width:600px">
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">E-mail</td>
    <td style="width:500px; padding:5px; border:1px solid #444">[email protected]</td>
  </tr>
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">Message</td>
    <td style="width:500px; padding:5px; border:1px solid #444">sometext</td>
  </tr>
</table>

当我测试它时,它看起来很好: alt text

当我通过 PHP mail() 函数发送它时,它看起来像这样: alt text

为什么会有这个边距?

以防万一,我的 mail() 标头是:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

I have a simple table:

<table cellpadding="0" cellspacing="0" style="width:600px">
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">E-mail</td>
    <td style="width:500px; padding:5px; border:1px solid #444">[email protected]</td>
  </tr>
  <tr>
    <td style="width:100px; padding:5px; border:1px solid #444">Message</td>
    <td style="width:500px; padding:5px; border:1px solid #444">sometext</td>
  </tr>
</table>

When I test it, it looks fine:
alt text

When I send it through PHP mail() function, it looks like this:
alt text

Why is that margin there?

Just in case, my mail() headers are:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-10-06 02:05:44

表格的宽度是 600 像素。

单元格的宽度加起来如下:

第一个单元格:1px 边框 + 5px 内边距 + 100px 宽度 + 5px 内边距 + 1px 边框 = 112px
第二个单元格 1 像素边框 + 5 像素内边距 + 500 像素宽度 + 5 像素内边距 + 1 像素边框 = 512 像素

总宽度:600 像素宽度表格中的 624 像素。

这可能不是问题,但我敢打赌这没有帮助。

我建议你先纠正这个问题,然后看看会发生什么。

The width of your table is 600px.

The width of the cells adds up as follows:

First cell: 1px border + 5px padding + 100px width + 5px padding + 1px border = 112px
Second cell 1px border + 5px padding + 500px width + 5px padding + 1px border = 512px

Total width: 624px in a 600px width table.

This may not be the problem, but I bet it is not helping.

I suggest you correct this first and then see what happens.

锦上情书 2024-10-06 02:05:44

您是否有机会在 mail() 的行之间插入 \n\r ?

did you by any chance insert \n\r between the rows in mail()?

紫瑟鸿黎 2024-10-06 02:05:44

好吧,想通了 - 问题是我在发送之前做了 nl2br($message)
($message包含上面的HTML代码)

但是谢谢大家的参与!

Well, figured it out - the problem was that I did nl2br($message) before sending.
($message contains the above HTML code)

But thank you all for participation!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文