Home / Integrations / Wordpress / Contact form 7 Dynamic Attachments using custom upload field

About The Moo Master

17 comments

  1. Dear Moo Master,

    I’ve being trying your method but does not seems to be working.

    I only get the [_dynamic_attachments] shortcode in return of the email..

  2. thanks for the code,

    But it does not work for me, I’ve done it step by step and it does not work.

    I am using:

    [_attachment_url]
    [_dynamic_attachments]
    [Dynamic_attachments]

    and it does not work.

    • Hi Marcos,

      Do you receive any error when testing either [_attachment_url] or [_dynamic_attachments] ?

      • It does not show any error, the message that arrives by email does not have the link of the complete file. Only displays the [_dynamic_attachments] tag without the link.

        Here’s what I’m using:

        Plugin configured: Just Custom Fields

        Functions.php:

        Add_filter (‘wpcf7_special_mail_tags’, ‘dynamic_attachments’, 20, 3);
        Function dynamic_attachments ($ output, $ name, $ html)
        {
           $ Name = preg_replace (‘/^wpcf7\./’, ‘_’, $ name);
           If (‘_dynamic_attachments’ == $ name) {
                $ Url = explode (‘?’, ‘Http: //’.$_SERVER [“HTTP_HOST”]. $ _SERVER [“REQUEST_URI”]);
                $ ID = url_to_postid ($ url [0]);
                $ Attachment_id = get_post_meta ($ ID, ‘_acf_uploadfield’, true);
                $ Output = wp_get_attachment_url ($ attachment_id);
           }
           Return $ output;
        }

        ——————————————–
        Form

        Append purchase invoice (required)
            [File * UploadResume limit: 10000000 filetypes: jpg | pdf | word | png | gif | jpeg]

        E-mail:

        From: [your-name]
        Subject: [cf7-counter-rma]

        Message body:
        [Your-message]

        Serial number: [serie-755]
        Purchase Invoice: [UploadResume]
        [_dynamic_attachments]

        • Hi Marcos,

          Sorry for my very late reply on this one – I’ve noticed since the latest version of CF7 there was a change.

          Please update to the new version of my code and it should work now.

          In particular, the following lines changed
          $submission = WPCF7_Submission::get_instance();
          $url = $submission->get_meta( ‘url’ );
          $ID = url_to_postid($url);

          Best regards,
          MooMaster

  3. Dear Moo Master,

    Still cant get it to work.

    I have the same output even after updating the code

    And when I use the second option i just get this: “/” without quotes.

    Kind Regards

  4. Thank you so much Moo Master !!

    That did the trick.

    Regards

  5. Is there any way to get the uploaded file to be included as an attachement to the email instead of just a link to the file?

    I want the physical file to go out with the email not just a link

    any help on this would be greatly appreciated.

    • Hi Jacques,

      Please try the code in the second example
      “OPTION 2: Attachment relative root path”
      And then place the shortcode into the attachment field (Make sure you’re using HTML as the content type for the CF7 Email)

      Best regards,
      MooMaster

  6. Thanks for the quick response but this does not appear to be working

    I think it may have to do with the fact that contact form 7 docs here state the following
    https://contactform7.com/file-uploading-and-attachment/

    When the path is not an absolute path, it will be treated as a relative path to wp-content directory.

    So it’s expecting

    uploads/test-attachement.pdf

    but this function is outputting

    /wp-content/uploads/test-attachement.pdf

    I think to get this to work the /wp-content/ needs to be removed from the output

    Can you make a suggestion on how to modify that happy to send beer money in exchange for your assistance with this.

    • Ok I figured out how to modify the output string like so

      $output = ‘uploads/’ . rawurlencode( basename( $parsed[ ‘path’ ] ) );

      so now the short code is outputting

      uploads/test-attachement.pdf

      I put [_dynamic_attachments] in the File Attachements field and have use HTML content type checked but it’s still not working.

      If I had code
      uploads/test-attachement.pdf in the Files attachement box it works. It seems like the short code is not running in the file attachement area.

    • Hi Jacques,

      Modified version of some similar code i’m using. Please try out the below.

      https://pastebin.com/R7swidHD

      If it works, feel free to send beer to 1FfLqTnYABc6K3Cy75eKD5PCEbyqU7pK3d 🙂

      Best regards,
      MooMaster

      • Thanks but still not working

        I tried both [moometric_dynamic_attachments] and [moometric_dynamic_attachments] in the file attachements dialog box of the but no luck.

        Also not sure how to send funds to 1FfLqTnYABc6K3Cy75eKD5PCEbyqU7pK3d what is that reference number?

        Jacques Choquette
        [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *