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来使用其他编码,您所要做的就是设置分隔符(在本例中为“------------”),以表示新文件开始。

更多相关文章

  1. 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
  2. 【MySQL 技巧分享】 mysql -e 加 v 简化代码
  3. Oracle相当于MySQL代码“插入虚拟”以返回错误消息
  4. 登录使用PHP并´t显示任何html代码
  5. 在代码点火器中从mysql迁移到postgresql
  6. 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
  7. 简单的插入语句不能在PHP代码中工作。适用于MySQL Workbench
  8. MYSQL错误代码和消息
  9. PO,Hibernate,VO,struts,spring,hibernate,Jsp,Oracle,mysql,mss

随机推荐

  1. PC通过USB连接Android通信(Socket)
  2. android 各系统区别(android 1.5- androi
  3. android 处理鼠标滚轮事件
  4. Android 全屏显示的两种方法
  5. android之实现各个组件点击事件处理
  6. RadioGroup和RadioButton的使用记录
  7. Android 微信分享,微信分享图片
  8. android :FTPServer
  9. Android示例HelloGallery中R.styleable u
  10. Android实现程序前后台切换效果