I am using a contact form 7 plugin for an inquiry form and sending the visitor 2 local files attached to the reply email. The function I used is this:
function my_dynamic_attachments($cf7)
{
$submission = WPCF7_Submission::get_instance();
$submission->add_uploaded_file('toe', get_template_directory().'/attachment1.pdf');
$submission->add_uploaded_file('ep', get_template_directory().'/attachment2.pdf');
}
add_action( 'wpcf7_before_send_mail', 'my_dynamic_attachments', 10 );
The problem I am facing is that the attachments are deleted from the server after the email is sent, thus they are not available for the next visitor. Is there any way to prevent this from happening?
Thank you in advance!
1 Answer
Looking at submit()
in WPCF7_Submission
we see a call to remove_uploaded_files()
which has no filter to stop it. So apparently what you are trying to do isn’t meant to be done by the author of CF7.
So apart from getting the author to include a hook there the only way I see is that you generate your file and then create a copy before adding it to the form submission so your original file stays.