创建 HTML 电子邮件时,我们应该使用 html、head、body 标签吗?

发布于 2024-09-27 05:45:49 字数 455 浏览 5 评论 0原文

在我的电子邮件视图中,我通常只是做类似的事情...

<dl>
   <dt>Name</dt>
   <dd>Value</dd>
</dl>

我应该这样做吗?

<html>
  <head></head>
  <body>
    <dl>
       <dt>Name</dt>
       <dd>Value</dd>
    </dl>
  </body>
</html>

换句话说,就像我在标记一个独立的文档一样?

我想我可以放心地假设任何基于网络的电子邮件客户端都会将其删除?

正确的方法是什么?

In my email views, I usually just do something like...

<dl>
   <dt>Name</dt>
   <dd>Value</dd>
</dl>

Should I be doing it like this?

<html>
  <head></head>
  <body>
    <dl>
       <dt>Name</dt>
       <dd>Value</dd>
    </dl>
  </body>
</html>

In other words, like I was marking up a standalone document?

I guess I can safely assume any web based email client will strip it out?

What is the right way?

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

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

发布评论

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

评论(6

等数载,海棠开 2024-10-04 05:45:49

正确的方法是遵循 HTML 标准。您可以在此处验证您的 HTML 页面。

您的邮件客户端应该遵循它,并且应该丢弃不支持或不安全的内容,例如 JavaScript。

我将揭示以下标准在这里可能有益的一些原因:

  1. 愿意将您的邮件显示为整页的网络邮件,可以保留您的格式。
  2. 网络邮件将简单地删除它不需要的标签和属性。但你永远不知道是哪些。
  3. 更容易找到遵循格式标准的(服务器端)组件,因此更不容易出错。不遵循标准的解析器可能会崩溃,导致您的电子邮件无法显示。

The right way is to follow the HTML standard. You can validate your HTML page here.

Your mail client should follow it and should throw away what's not supported or what's insecure, like JavaScript.

I'll expose some reasons why following standards could be beneficial here:

  1. a webmail willing to show your mail as a full page, could keep your format.
  2. a webmail will simply strip the tags and attributes it doesn't want. But you can never know which ones.
  3. It's easier to find (server side) components that follow format standards, and thus are less error prone. Parsers not following standards could possibly break, making your email not getting shown.
↙温凉少女 2024-10-04 05:45:49

无论是否包含 html/head/body 标记都完全无关 - 它们始终是可选的,不会以任何方式影响文档的呈现。

最重要的是怪异模式是否开启。不幸的是,您无法在网络邮件设置中控制它。表格和内联样式是您的朋友。最好的选择是在尽可能多的网络邮件和桌面客户端中进行测试。

Whether or not you include the html/head/body tags is entirely irrelevant — they are always optional and will not affect the rendering of the document in any way.

What matters most is whether quirks mode is on or not. Unfortunately, you can’t control that in a webmail setting. Tables and inline styles are your friends. Your best bet is to test in as many webmail and desktop clients as you can.

清欢 2024-10-04 05:45:49

该线程上的许多帖子都相当陈旧,因此它们不再准确。

如今,如果您打算做任何花哨的事情,HTML 电子邮件应该包含文档类型、html 和正文声明。

关于这个主题有很多指南可以帮助您学习如何正确编码 HTML 电子邮件,但大多数指南都忽略了文档类型的细节,这就是我偶然发现您的问题的原因。

我建议您阅读以下两篇文章,它们来自熟悉各种问题的知名团队:

活动监视器的记录

关于 Acid 的电子邮件

Many of the posts on this thread are rather old, and as a result they are no longer accurate.

These days HTML emails should include a doctype, html and body declaration if you intend to do anything fancy at all.

There are a multitude of guides on this subject which can help you learn how to properly code HTML Email, but most of them disregard the specifics of a doctype, which is how I stumbled on your question.

I suggest you read the following 2 posts which are from reputable teams familiar with the various problems:

campaign monitor's take

email on acid's take

云归处 2024-10-04 05:45:49

完全取决于接收它的电子邮件客户端。根据我的经验,大多数解释 HTML 的电子邮件客户端并不关心您是否有完整的 body/head/html 标签等。事实上,大多数浏览器甚至不需要这些标签。您需要有头标签来包含样式/标题等。否则它们本身并不是真正必要的。我从来不认为它们是必要的。

Depends entirely on the email client that receives it. In my experience, most email clients that will interpret HTML don't care if you have full body/head/html tags, etc. In fact you don't even need those tags for most browsers. You need to have the head tags to include style/title, etc. Otherwise they are not really necessary, per se. I've never seen them to be necessary.

任谁 2024-10-04 05:45:49

我知道有一件事是正确的:使用 HTML 开始和结束标签将有助于一般垃圾邮件评分,因为许多此类基于设备的过滤器和软件防火墙会向使用 html 但不使用 html 的电子邮件添加一个点左右开始和结束标签。

There's 1 thing I know to be true: Using HTML opening and closing tags will help in general spam scoring due to the fact that many such appliance based filters and software firewalls will add a point or so to an email that uses html but does not use the opening and closing tags.

梦行七里 2024-10-04 05:45:49

我认为没有正确的方法,但尝试让电子邮件在尽可能多的电子邮件阅读器中可见。

我通常在 Thunderbird 中查看电子邮件,因为 Outlook 更宽容。

在 Thunderbird 中,这是电子邮件的 HTML 代码(我有一个显示 html 的扩展)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
        This is the body text<br>
<div class="moz-signature"><i><br>
<br>
Regards<br>
Alex<br>
</i></div>
</body>
</html>

顺便说一句,我每次都对所有网络表单使用纯文本电子邮件。我在使用 html+纯文本电子邮件发送黑莓电子邮件时遇到了很多问题。

I don't think there is a right way but trying to make the email viewable in as many email readers as posible.

I usually check the emails in Thunderbird, because Outlook forgives more.

In Thunderbird this is the HTML code for an email (i have an extension that shows the html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
        This is the body text<br>
<div class="moz-signature"><i><br>
<br>
Regards<br>
Alex<br>
</i></div>
</body>
</html>

BTW, i use plain text email for all my web forms every time I can. I had many issues with blackberry email using html+plain text emails.

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