I'm trying to send a dynamic pdf that is attached to a post via the plugin contact form 7.

I assume I need to use the hook:


As it's been the hook I've seen used most commonly when looking for a solution.

Here's what I have, I've just been trying with a test pdf with an absolute url first:

function send_pdf( $cf7 ) {
    if ($cf7->id==741){
        $cf7->uploaded_files = array ( 'pdf' => get_template_directory().'/test.pdf' );

Now if I understand this correctly, if the contact form id is correct, and I have [pdf] in the mail2 "file attachment" field, then that pdf should send via email to the person who has submitted their details?

For me though this isn't working, I get the email but with no attachment.

Is there something I'm missing here or perhaps know of another method that works?

closed as off-topic by Pieter Goosen, Mark Kaplun, Mayeenul Islam, gmazzap, Wyck Jan 27 '15 at 22:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


Try this instead. There was some internal restructuring in CF7 3.9.


function send_pdf( $cf7 ) {
    $id = $cf7->id();
    if ($id==741){
        $submission = WPCF7_Submission::get_instance();
        $submission->add_uploaded_file('pdf', get_template_directory().'/test.pdf');

This should work.

  • You beautiful person, works great. Oh you might want to add a slash before test.pdf that was a typo on my behalf. Might confuse people who use it :) – UzumakiDev Jan 24 '15 at 18:55
  • 1
    Good call on the typo. Glad it works! – WordPress Mike Jan 24 '15 at 18:58
  • I don't suppose you know why that test.pdf url worked by a url like /wp-content/uploads/2015/01/test.pdf does not? Something to do with plugin permissions? – UzumakiDev Jan 24 '15 at 20:13
  • Are you hard coding the URL? – WordPress Mike Jan 25 '15 at 20:54
  • I think you need an absolute path. You might try get_home_path(); I can't test right now but let me know if it works. – WordPress Mike Jan 25 '15 at 21:33

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