Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:22:41+00:00 2026-06-01T01:22:41+00:00

I am using the following loop to send/attach multiple attachments to my email message.

  • 0

I am using the following loop to send/attach multiple attachments to my email message.

foreach(array_keys($_FILES['attachment']['name']) as $key) {
    $source = $_FILES['attachment']['tmp_name'][$key]; 
    $filename = $_FILES['attachment']['name'][$key]; // original filename from the client
    $mail->AddAttachment($source, $filename);
}

But only the first attachment i made is sended.

The form code is

<form method="POST" action="<?php $PHP_SELF ?>"  enctype="multipart/form-data">
<input type="file" name="attachment[]" id="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>
<input name="submit" type="submit" value="submit" />
</form>

When one click on Attach another file, another File Upload button is shown, through a JavaScript function:

<script type="text/javascript">
var upload_number = 1;
var attachmentlimit = 5;
function addFileInput() {
    var d = document.createElement("div");
    var file = document.createElement("input");
    file.setAttribute("type", "file");
    file.setAttribute("name", "attachment"+upload_number);
    d.appendChild(file);
    document.getElementById("moreUploads").appendChild(d);
    upload_number++;
    if(upload_number == attachmentlimit) {
          document.getElementById('moreUploadsLink').style.display='none';
    }
}
</script>

Only the file attached through the first FileUpload Button is attached and sended, not the others.
Help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:22:43+00:00Added an answer on June 1, 2026 at 1:22 am

    The problem is that you are setting the name attribute of your new input element to attachment1, attachment2, etc. You should be setting this name to attachment[], just like the original input you created.

    If you still don’t get all your attachments, you can try a var_dump($_FILES) in your PHP script to ensure that you are getting all the files the way you expect them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following loop to add items to an an array. I
I am using the following function to loop through a couple of open CDB
I am using the following command in a bash script to loop through directories
I am using the following loop to traverse an array where i need both
I m using the following loop , but its only typing the first charecter
I'm using the following loop to grab files for an animation. This method makes
I am using grails Async Mail plugin to send emails with attachments in my
I am using following code myEl = document.createElement(myElement) ; //in a loop myEl.innerHTML =
I am trying to build an automated email that will send attachments based on
I have been using the following code to loop through specific classes in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.