只有第一个附件通过php邮件发送

时间:2012-03-26 18:18:46

标签: php javascript phpmailer

我正在制作一个表单,通过多个上传框上传多个附件: 我通过javascript函数添加文件上传,附加更多文件上传框,最多5个框:

<input type="file" name="attachment[]" size="30"
onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
 <div id="moreUploads"></div>
 <div id="moreUploadsLink" style="display:none;">
 <a href="javascript:addFileInput();">Attach another File</a></div>

在选择中,通过javascript,它会要求“附加另一个文件”,点击它后,它最多可提供5个上传文件,

问题是当我尝试发送包含所有附件的邮件时,只发送第一个附件: 要发送的循环是

   $numFiles = count($_FILES['attachment']['name']);
   for ($i = 0; $i < $numFiles; ++$i) 
{
 $target_path = "uploads/";
     $target_path = $target_path . basename($_FILES['attachment']['name'][$i]);
     if(move_uploaded_file($_FILES['attachment']['tmp_name'][$i], $target_path)) {
     echo "the file ".basename($_FILES['attachment']['name'][$i])." has been uploaded
     <br/>";
 }
 $mail->AddAttachment($target_path);
 }

请任何身体帮助

0 个答案:

没有答案