我希望发送一封包含多个附件的php的电子邮件。我已经做了大量的谷歌搜索,并尝试了许多不同的脚本,但无论我做什么,电子邮件要么完全贴上标签,没有附件,或者包含第一个附件,其余的则被丢弃。这是我到目前为止的代码。
$to = '...';
$subject = 'afdgafg';
$message = "check it";
$filename = "updates";
$filename2= "updates2";
$filename3 = "updates3";
$content = chunk_split(base64_encode("womp womp womp"));
$content1 = chunk_split(base64_encode("wadfgafdgomp womp womp"));
$content2 = chunk_split(base64_encode("womp wompadfgafgafdg womp"));
$uid = md5(uniqid(time()));
$from = "tearsheet reports";
$from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection
$header = "From: ".$from."\r\n"
."MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
."This is a multi-part message in MIME format.\r\n"
."--".$uid."\r\n"
."Content-type:text/plain; charset=iso-8859-1\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
.$message."\r\n\r\n"
."--".$uid."\r\n"
."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
.$content."\r\n\r\n"
."Content-Type: application/octet-stream; name=\"".$filename2."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename2."\"\r\n\r\n"
.$content1."\r\n\r\n"
."Content-Type: application/octet-stream; name=\"".$filename3."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename3."\"\r\n\r\n"
.$content2."\r\n\r\n"
."--".$uid."--";
mail($to, $subject, $message, $header);
我可以收到电子邮件,但它只有1个附件,而不是我想要的3个。我不想使用像phpmailer这样的库,因为这将在生产服务器上运行,因此依赖性越小越好。有什么建议吗?