用于上传多个文件的PHP代码
16lz
2021-01-22
I have a function code with which you can send letters to the attached file. How to modify this code to send multiple files?
我有一个功能代码,您可以使用该代码将信件发送到附件。如何修改此代码以发送多个文件?
function xmail($from, $to, $subj, $text, $filename)
{
$f = fopen($filename, "rb");
$un = strtoupper(uniqid(time()));
$head = "From: $from\n";
$head .= "To: \n";
$head .= "Subject: \n";
$head .= "X-Mailer: PHPMail Tool\n";
$head .= "Reply-To: $from\n";
$head .= "Mime-Version: 1.0\n";
$head .= "Content-Type:multipart/mixed;";
$head .= "boundary=\"----------" . $un . "\"\n\n";
$zag = "------------" . $un . "\nContent-type: text/plain; charset=utf-8\n";
$zag .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n";
$zag .= "------------" . $un . "\n";
$zag .= "Content-Type: application/octet-stream;";
$zag .= "name=\"" . basename($filename) . "\"\n";
$zag .= "Content-Transfer-Encoding:base64\n";
$zag .= "Content-Disposition:attachment;";
$zag .= "filename=\"" . basename($filename) . "\"\n\n";
$zag .= chunk_split(base64_encode(fread($f, filesize($filename)))) . "\n";
return @mail("$to", "$subj", $zag, $head);
}
2 个解决方案
#1
1
You do already have two attachments, so just add others by:
您已经有两个附件,所以只需添加其他附件:
$zag .= "------------" . $un . "\n";
$zag .= "Content-Type: application/octet-stream;";
$zag .= "name=\"" . basename($otherFilename) . "\"\n";
$zag .= "Content-Transfer-Encoding:base64\n";
$zag .= "Content-Disposition:attachment;";
$zag .= "filename=\"" . basename($otherFilename) . "\"\n\n";
$zag .= chunk_split(base64_encode(fread($otherFile, filesize($otherFilename)))) . "\n";
You could also use other encodings by setting other Content-Transfer-Encoding
, all you got to do basically is to set the delimiter ("------------"
in this case), to signal that a new file begins.
您还可以通过设置其他Content-Transfer-Encoding来使用其他编码,您所要做的就是设置分隔符(在本例中为“------------”),以表示新文件开始。
更多相关文章
- 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
- 【MySQL 技巧分享】 mysql -e 加 v 简化代码
- Oracle相当于MySQL代码“插入虚拟”以返回错误消息
- 登录使用PHP并´t显示任何html代码
- 在代码点火器中从mysql迁移到postgresql
- 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
- 简单的插入语句不能在PHP代码中工作。适用于MySQL Workbench
- MYSQL错误代码和消息
- PO,Hibernate,VO,struts,spring,hibernate,Jsp,Oracle,mysql,mss