Question
Wordpress. Contact Form 7. How to add several attachments in email using code?
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 26
2