Dynamically Attach Files in Contact Form 7 Email
-
Hi, I have a simple registration form that contain only user details like name, email address, and a and a drop-down menu with two options. Each option refers to a different type of ebook’s files format (pdf, jpg).
The form uses Mail(2) as an autoresponder back to the person filling the form in. Based on the value of the drop-down menu, I would like to select the file format to be sent.
Unfortunately, at present the form does not send emails and appears a orange border error, showing this message: “There was an error trying to send your message. Please try again later.”
-The attachments are presents in my uploads folder (i.e. uploads/2020/07/name-of-file).
-File attachments set up:
form tag: [file SelezioneFile filetypes:pdf|jpg]
mail tag: [Selezionefile]
Field: File attachments (in mail tab panel)– Form id: 2913
– Form Name: Test DownloadMoreover, to identify the file to attach I used the path to the get_template_directory_uri() and uploads folder. I specified an identifier (SelezioneFile) for the file attachments, in order to select which files to attach.
Then i added this to my functions.php file:
===============================================================
add_action( ‘wpcf7_before_send_mail’, ‘my_dynamic_attachments’ );
function my_dynamic_attachments($cf7)
{
//check if it is the registration form
if (2913 == $WPCF7_ContactForm->id())
{
// get the dropdown menu value and the corresponding file
$filename = get_Selezionefile_filepath($cf7->form[‘Test-Download’]);$cf7->uploaded_files = array(‘Selezionefile’=>$filename);
}
}
=================================================================
Finally, the active plugins are the following:– Cookie Notice
– Elementor
– Elementor – Header, Footer & Blocks
– Google Analytics for WordPress by MonsterInsights
– ImageMagick Engine
– Limit Login Attempts Reloaded
– PHP Compatibility Checker
– Social Icons Widget & Block by WPZOOM
– wpDiscuzCan you advise where I went wrong?
The page I need help with: [log in to see the link]
- The topic ‘Dynamically Attach Files in Contact Form 7 Email’ is closed to new replies.