Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter LESIMOON

    (@lesimoon)

    any idea?

    Thread Starter LESIMOON

    (@lesimoon)

    I will explain a bit more:

    I inserted the contact form on a page who generate a .pdf with a custom name ($name.pdf).
    I want to attach this generated file in the mail ( the/file/path/$name.pdf)
    How can I do it?

    I’m very interested too. I need to include variable in email, like a $number.

    If it would be enough to add a https://the/file/whatever.pdf download link to the mail (instead of attaching the file), one simple way (which requires some programming skills) would be a CF7 text field with a custom id which is hidden via css and filled with file URL via javascript on your contact page similar to this.

    Thread Starter LESIMOON

    (@lesimoon)

    It won’t work for me, because the the .pdf file is deleted of the server after 15 min.

    I tried a trick without any success. I added a hidden field with value=”<?php echo”/Path/To/File/”.$name.”.pdf”?>” in CF7 shortcode [FileURL].

    I put the shortcode [FileURL] in the mail content and it appear like it should.
    But when it doesn’t work when I but it in the File Attachment ??

    You can’t attach a file in a hidden field.

    You could alter the email data before sending via wpcf7_before_send_mail filter in PHP, similar to this example (untested, edit: new link), found via a websearch.

    Thread Starter LESIMOON

    (@lesimoon)

    My hidden filed was actually a string containing the .pdf url.
    Thank you for you help, gonna take a look at those link !

    I think problem is, you can’t add code include <form> element just on page/theme. Maybe I’m wrong.

    It can be Form7 hack, but I think better wait for other solution, maybe is easy and ready done by Form7 author.

    Thread Starter LESIMOON

    (@lesimoon)

    Alright, I tried it, it’s working with a determined file.
    But the file I want to send will never be the same. (“$name”.pdf)
    $submission->add_uploaded_file('pdf', 'path/to/test.pdf');
    I understood (at least I think), ‘pdf’ is the cf7 shortcode for [pdf].
    Maybe I can use my [HiddenShortcode] to complete the pdfname in the path, but how?

    $submission->add_uploaded_file('pdf', 'path/to/'.[HiddenShortcode].'.pdf');
    (The above code is obviously wrong, but it’s just to explain a bit more.

    Thread Starter LESIMOON

    (@lesimoon)

    @facet :
    Take a look at this https://www.ads-software.com/support/plugin/contact-form-7-dynamic-text-extension

    Even if it won’t solve my problem it might solve your

    @lesimoon

    Thank you! I’m sure it can help, I will confirm later ??

    Thread Starter LESIMOON

    (@lesimoon)

    Alright, I finally solved my problem :

    add_action('wpcf7_before_send_mail','send_pdf');
    
    function send_pdf( $cf7 ) {
      $submission = WPCF7_Submission::get_instance();
      $data = $submission->get_posted_data();
      $path = $data['HiddenField'];
      $submission->add_uploaded_file('pdf', $path);
    }

    Thank you @ov3rfly for your help !

    @lesimoon

    I can confirm, it working GREAT ?? Thank you again.

    I think this short tutorial can help https://wptips.me/how-to-add-dynamic-values-into-contact-form-7-inputs/

    Congratulations and thanks for feedback and example code for other readers.

    @lesimoon: Please mark the topic as “resolved” in right hand side menu, thanks.

    Thread Starter LESIMOON

    (@lesimoon)

    Yeah was waiting Facet to solve his problem.
    Done.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘include php variable in mail’ is closed to new replies.