Attaching a pdf to Contact Form 7 e-mail via functions.php [closed]

I’ve found what’s been missing in the code. You have to add this also:

add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );

function mycustom_wpcf7_mail_components( $components ) {
    $components['attachments'][] = get_template_directory().'/pdf/test.pdf';

    return $components;
}

Now everything is working fine and the file is attached to email without the need to add fields in the contact form.