Title: dynamically attach multiple files
Last modified: August 21, 2016

---

# dynamically attach multiple files

 *  Resolved [Danielle](https://wordpress.org/support/users/secretfamiliesmc/)
 * (@secretfamiliesmc)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/)
 * Able to attach a single file dynamically in function.php file in my child theme
   directory, but having problems adding another file.
    Tried putting a /n between
   the file names, but that didn’t work. Please help.
 * Here’s a snippet of the code I’m using:
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       // get the dropdown menu value and the corresponding instruction file
              $myDocName =  $WPCF7_Form->posted_data['TeamType'].".pdf";
              $WPCF7_Form->mail_2['attachments'] = "uploads/Instructions/".$myDocName ;
              // attach team sign up sheet
               $WPCF7_Form->mail_2['attachments'] .= "/nuploads/Instructions/TeamSignUp.pdf";
       ```
   
 * My site:
    [http://www.staging.secretfamiliesmc.org/team-sign-up/](http://www.staging.secretfamiliesmc.org/team-sign-up/)
 * Thanks
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053655)
 * If you mean the meta character representing a new line, it’s `\n` , not `/n`.
 *  [Leo](https://wordpress.org/support/users/leonardomiguelneto/)
 * (@leonardomiguelneto)
 * [11 years ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053848)
 * secretfamiliesmc hello, sorry for my bad english, please can you tell me if this
   is how to apply the code? I’m days trying to implement this code without success,
   my data is acquired in drop-down box.
 *     ```
       add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components1' );
       function mycustom_wpcf7_mail_components1( $components ) {
   
        $myDocName = $WPCF7_Form->posted_data['Mesfatura'].".pdf";
       $components['attachments'] = "uploads/777/".$myDocName ;
   
           return $components;
       }
       ```
   
 * what I want is, with the data from drop-down [‘Mesfatura’] select a pdf attachment
   with the same name. Already tried hundreds of ways and I can’t find a solution.
   
   I would really appreciate any help you can give me.
 *  Thread Starter [Danielle](https://wordpress.org/support/users/secretfamiliesmc/)
 * (@secretfamiliesmc)
 * [11 years ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053849)
 * Sorry Leo, my code snippet is above. Actually this code doesn’t work anymore 
   since the last big update to the pluggin. I haven’t figured out how to implement.
   The pluggin documentation is not made for folks who aren’t coders. I will have
   to try again this summer to get it working. We haven’t updated to the new plugin
   on our live site due to the issues.
 *  [Leo](https://wordpress.org/support/users/leonardomiguelneto/)
 * (@leonardomiguelneto)
 * [11 years ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053850)
 * Thanks anyway, but I have to find a solution, I really need a code to attach 
   files dynamically with the data placed in the form.
 *  [Leo](https://wordpress.org/support/users/leonardomiguelneto/)
 * (@leonardomiguelneto)
 * [11 years ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053851)
 * I solved the problem with this code
 *     ```
       add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body');
       function wpcf7_update_email_body($contact_form) {
   
       $submission = WPCF7_Submission::get_instance();
       if ( $submission ) {
       /* DEFINE CONSTANT AND GET FPDF CLASSES */
       define ('PDF_PATH', 'wp-content/uploads/777/'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS PDF
   
       $posted_data = $submission->get_posted_data();
       // FORM FIELD DATA AS VARIABLES
       $mes = $posted_data['mes'];
       define ('PDF_PATH2', PDF_PATH.$mes.'.pdf');
       }
       }
   
       add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
       function mycustom_wpcf7_mail_components($components){
       if (empty($components['attachments'])) {
       $components['attachments'] = array( PDF_PATH2 ); // ATTACH THE PDF THAT WAS chosen ABOVE
       }
       return $components;
       }
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘dynamically attach multiple files’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Leo](https://wordpress.org/support/users/leonardomiguelneto/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/dynamically-attach-multiple-files/#post-5053851)
 * Status: resolved