Title: include php variable in mail
Last modified: August 31, 2016

---

# include php variable in mail

 *  Resolved [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/)
 * Hey, first of all thank you for this awesome plugin.
 * I created a custom wordpress template and included the CF7 plugin. Everything
   is working like a charm.
    But I was wondering if it was possible to add a PHP
   variable in the mail.
 * Cheers
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

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

 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976049)
 * any idea?
 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976055)
 * 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?
 *  [Facet](https://wordpress.org/support/users/facet/)
 * (@facet)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976067)
 * I’m very interested too. I need to include variable in email, like a $number.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976068)
 * If it would be enough to add a `http://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](http://stackoverflow.com/a/22943618).
 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976070)
 * 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 🙁
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976072)
 * 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](http://wordpress.stackexchange.com/a/175877)(
   untested, _edit:_ new link), found via [a websearch](https://www.google.com/search?q=cf7+attach+file+wpcf7_before_send_mail).
 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976073)
 * My hidden filed was actually a string containing the .pdf url.
    Thank you for
   you help, gonna take a look at those link !
 *  [Facet](https://wordpress.org/support/users/facet/)
 * (@facet)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976077)
 * 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](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976078)
 * 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](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976079)
 * [@facet](https://wordpress.org/support/users/facet/) :
    Take a look at this [https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension](https://wordpress.org/support/plugin/contact-form-7-dynamic-text-extension)
 * Even if it won’t solve my problem it might solve your
 *  [Facet](https://wordpress.org/support/users/facet/)
 * (@facet)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976081)
 * [@lesimoon](https://wordpress.org/support/users/lesimoon/)
 * Thank you! I’m sure it can help, I will confirm later 🙂
 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976082)
 * 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](https://wordpress.org/support/users/ov3rfly/) for your help!
 *  [Facet](https://wordpress.org/support/users/facet/)
 * (@facet)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976083)
 * [@lesimoon](https://wordpress.org/support/users/lesimoon/)
 * I can confirm, it working GREAT 🙂 Thank you again.
 * I think this short tutorial can help [http://wptips.me/how-to-add-dynamic-values-into-contact-form-7-inputs/](http://wptips.me/how-to-add-dynamic-values-into-contact-form-7-inputs/)
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976086)
 * Congratulations and thanks for feedback and example code for other readers.
 * [@lesimoon](https://wordpress.org/support/users/lesimoon/): Please mark the topic
   as “resolved” in right hand side menu, thanks.
 *  Thread Starter [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * (@lesimoon)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976087)
 * 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.

 * ![](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/)

 * 15 replies
 * 3 participants
 * Last reply from: [LESIMOON](https://wordpress.org/support/users/lesimoon/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/include-php-variable-in-mail/#post-6976087)
 * Status: resolved