创建 MIME 边界的规则(对于邮件附件)
我正在使用 PHP mail() 函数发送带有附件的邮件。 因此,PHP 源内容包含一个边界来定义附件的开始和结束位置。
所以问题是:创建这个 MIME 边界有什么规则吗(例如只允许使用字母和数字) 我仍然知道这个问题 -> 哪些规则适用于 MIME 边界? 是否有必要为 HASH 创建边界? 因为以下内容也适用:
$headers .= "Content-Type: multipart/related; boundary=\"abc\"";
[...]
$msg .="--abc\n";
[...]
$msg .= "--abc--\n\n";
是否有原因,为什么 MIME 边界应该是唯一的值?
..我在互联网上没有找到任何信息。
谢谢你!
i'm using the PHP mail() function to send mails with attachment.
Therefore the PHP source contents an boundary to define where the attachment begins and ends.
So the question is: are there any ruels for creating this MIME boundary (exampt that are only letters and numbres are allowed)
i still know this SO question -> What rules apply to MIME boundary?
Is it necessary to create an boundary form an HASH?
Because the following also works:
$headers .= "Content-Type: multipart/related; boundary=\"abc\"";
[...]
$msg .="--abc\n";
[...]
$msg .= "--abc--\n\n";
Is there a reason, why a MIME boundary should be an unique value?
..i didn't found any information at the Internet.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有什么规定边界标记必须是哈希值,但它们必须是唯一的。想象一下,如果您插入的实际电子邮件文本在某处自然包含单词
--abc--
,会发生什么。您的电子邮件看起来像这样:
那么...邮件客户端如何知道电子邮件的一部分以及“开销”是什么?这就是为什么你使用独特的边界。
哈希是最简单的方法。在极端情况下,电子邮件文本不太可能在可以被视为边界标记的确切位置包含自己的哈希值。
Nothing says the boundary markers have to be hashes, but they MUST be unique. Think of what would happen if the actual email text you're inserting naturally contains the words
--abc--
somewhere.Your email would look something like this:
So... How is a mail client to know what's part of the email and what's just "overhead"? That's why you use unique boundaries.
Hashes are simply the easiest method. It's unlikely in the extreme that an email text would happen to contain its own hash value in the exact spot where it could be seen as a boundary marker.
MIME 边界应该是不可能出现在用户的实际消息中的东西。哈希是一个不错的选择,因为它们很长且唯一。独特性还使得其他人很难通过弄清楚您使用的边界并将其包含在他们的消息中来搞乱他们的消息。但是,我找不到边界唯一的任何要求,只是整行少于 70 个字符。
MIME boundaries should be something impossibly unlikely to appear in the user's actual message. Hashes are a good option because they are long and unique. Uniqueness also makes it difficult for someone to mess up their messages by figuring out what boundary you use and including it in their message. However, I can't find any requirement that boundaries be unique, just that the entire line be under 70 characters.