Trying to add attachments to the letter.
add_action('wpcf7_before_send_mail', 'custom_attach_files_to_email');
function custom_attach_files_to_email($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$uploaded_files = $submission->uploaded_files();
$attachments = array();
foreach ($uploaded_files as $uploaded_file) {
$attachments[] = $uploaded_file;
}
$attachments[] = WP_CONTENT_DIR . '/uploads/files/file.txt';
//$attachments[] = WP_CONTENT_DIR . '/uploads/files/file_2.txt';
$mail = $contact_form->prop('mail');
$mail['attachments'] = implode(',', $attachments);
$contact_form->set_properties(array('mail' => $mail));
}
}
This works only for ONE file. When i try to send two files (file.txt and file_2.txt) – the letter has no files at all
I need to send several files using code.
2
Answers
so, this code sends a letter with files. it's very important to set the correct path to file and files shouldn't be empty. also this code removes all attached files before (i didn't find no more ways)
}
To properly attach multiple files in Contact Form 7, ensure that the attachments are set as an array in the mail properties. Try this code:
Make sure the file paths are correct and that the files exist