Dynamically send pdf attached to post with contact form 7 [closed]

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:

add_action('wpcf7_before_send_mail','send_pdf');

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?

1 Answer
1

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

add_action('wpcf7_before_send_mail','send_pdf');

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.

Leave a Comment