1

I need to add the ability to have multiple attachments from the input field on my Wordpress site. Currently I used jQuery code to clone the input field and assign new ID and name with increment of 1.

The problem is no matter how many attachments I upload and send, only the first one gets delivered in mailbox. I checked Wordpress codex and found wp_mail function that should do what I need, but I need tweak it for taking multiple attachments. Code below:

    $attachments = array( WP_CONTENT_DIR . '/uploads/file_to_attach.zip' );
    $headers = 'From: My Name <myname@example.com>' . "\r\n";
    wp_mail( 'test@example.org', 'subject', 'message', $headers, $attachments );



    jQuery('document').ready(function() {
    var cloneCount = 1;
    var cloneCount2 = 1;
    jQuery('.file-upload').on('click', function(){
    jQuery('#file-image')
       .clone()
       .attr({id: 'file-image'+ cloneCount++, name: 'file-image'+ cloneCount2++})
       .insertAfter(jQuery('[id^=file-image]:last'))
    }); 
 });

    <span class="file-upload">
       <input name="file-image" size="40" id="file-image" aria-invalid="false" type="file">
    </span>
-2

Did you try this plugin? Multifile Upload Field for Contact Form 7

  • I know it but haven't tried it yet, from what I read it zips the attachments. Might try if all other solutions fail. Thanks! – Radi Nov 1 '17 at 12:21
  • I guess I will stick with your answer for now. – Radi Nov 1 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.