【发布时间】:2015-04-07 12:58:16
【问题描述】:
最近我遇到-- 作为 php 中mail() 函数的标头。我试图用谷歌搜索,但没有找到任何结果,所以我发布了这个问题。在尝试编辑我的代码时,我发现这两个 -- 之后的 id 应该是唯一的。我的 php 脚本发送带有附件的电子邮件。
<?php
$file = "http://wpbrisk.com/download/email/email/doc1.pdf"; // Specify the Url of the attachment here
$filename = "doc1.pdf"; // Specify the name of the file here
$to="hudixt@gmail.com"; // Enter the mail to which you want to sent the attachement
$your_name = "Hudixt"; // Your name
$from_mail = "info@wpbrisk.com"; // Your email
$subject = "This is a mail with attachment."; // Subject
$message = "<div id='hello'>World</div>"; // message
// Get the content of the file
$content = file_get_contents($file);
$content = base64_encode($content);
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
mail($mailto, $subject, "", $header);
?>
你能告诉我这个--在标题中的含义以及为什么它应该是唯一的。
【问题讨论】:
-
请发布所有相关代码和您正在谈论的上下文。我想这与 MIME 部分边界有关,对吧?
-
双破折号是某些格式的注释,可能就是这样
-
对我来说似乎有些界限
-
如果我必须做出有根据的猜测,我会说它们是边界。见en.wikipedia.org/wiki/MIME#Multipart_messages
-
@MrTux 和其他人你能告诉我为什么这些边界应该是独一无二的以及它们需要什么