Closed smile00000 closed 4 months ago
+1
@smile00000
Currently, this feature is not supported, but we will look into it in the future if we see a large demand for it.
for now, you can use this class which will add the uploads as attachments to the email:
See this updated version which allows removing the files from the server after they are sent: https://github.com/pojome/elementor/issues/4868#issuecomment-458906081
<?php
/**
* Class Elementor_Form_Email_Attachments
*
* Send Elementor Form upload field as attachments to email
*/
class Elementor_Form_Email_Attachments {
public $attachments_array = [];
public function __construct() {
add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 );
}
/**
* @param \ElementorPro\Modules\Forms\Classes\Form_Record $record
* @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler
*/
public function init_form_email_attachments( $record, $ajax_handler ) {
// check if we have attachments
$files = $record->get( 'files' );
if ( empty( $files ) ) {
return;
}
// Store attachment in local var
foreach ( $files as $id => $files_array ) {
$this->attachments_array[] = $files_array['path'][0];
}
// if local var has attachments setup filter hook
if ( 0 < count( $this->attachments_array ) ) {
add_filter( 'wp_mail', [ $this, 'wp_mail' ] );
add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 );
}
}
public function remove_wp_mail_filter() {
$this->attachments_array = [];
remove_filter( 'wp_mail', [ $this, 'wp_mail' ] );
}
public function wp_mail( $args ) {
$args['attachments'] = $this->attachments_array;
return $args;
}
}
new Elementor_Form_Email_Attachments();
Thanks for the feedback.
Thank you for the code, do we put this in the CSS box of the elementor widget?
I asked Elementor Support how to install this:
"Hi, nope, I guess this must be added to the theme's functions.php file at the end of it.Best regards. " That is not an ideal workaround then. We already have a +1 on this feature request. Can't you keep it open to see if others want it as well?
It's here and labeled so no need to keep it open if we get many new requests then ....
thanks.
Please make this happen, I have bought E Pro for the form widget but now I'm using Form7 instead while waiting for that issue to be resolved. Thank you
Hello! This Code is great for me, but I have a question:
With this code the attachements are in my boxemail but these are in FTP too... Any posibility these files aren´t in FTP?
I received a lot of attachements and I need remove these all weeks.
Thank you!
+1
good day I do not know how to reach you and explain I'm writing this letter for the tenth time ! finally, pay attention to the form of sending a message . the problem is as follows . when attaching the file it went to the hosting path /CLAIFLOWER//uploads / elementor / forms and the files are downloaded to the folder . what is it ? the file should come to the post office and then it turns out the mail comes with a link to the specified file and folder https://claiflower.ru/wp-content/uploads/elementor/forms/5c19d6c2038c7.jpg this is wrong . if we consider the security on the hosting can get malicious files through the submission form . moreover, the hosting where the site is located limit Disk space: 20.0 GB it thus becomes clogged . I bought your elementor for website design and correct work and it turns out the money was spent in vain .
................................................................................ What about the code is not an option! need to solve this problem. I bought about the version and I suffer with it for a long time and more than once wrote silence only in response. Dear developers, you sell your creation should work out as this product is paid.
Hi bainternet, Does this mean that it has been resolved? Thank you
good day unfortunately there is nothing fixed when attaching the file, they are still loaded on the FTP server in the folder uploads/elementor/forms
добрый день к сожалению нет ничего не исправили при креплении файла они все равно загружаются на фтп сервер в папку uploads/elementor/forms
good day unfortunately there is nothing fixed when attaching the file, they are still loaded on the FTP server in the folder uploads/elementor/forms добрый день к сожалению нет ничего не исправили при креплении файла они все равно загружаются на фтп сервер в папку uploads/elementor/forms https://prnt.sc/m8jffa
Среда, 16 января 2019, 17:00 +03:00 от Christian notifications@github.com:
Hi bainternet, Does this mean that it has been resolved? Thank you — You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .
-- Алексей Теняков
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php
/**
* Class Elementor_Form_Email_Attachments
*
* Send Elementor Form upload field as attachments to email
*/
class Elementor_Form_Email_Attachments {
// Set to true if you want the files to be removed from
// the server after they are sent by email
const DELETE_ATTACHMENT_FROM_SERVER = false;
public $attachments_array = [];
public function __construct() {
add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 );
}
/**
* @param \ElementorPro\Modules\Forms\Classes\Form_Record $record
* @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler
*/
public function init_form_email_attachments( $record, $ajax_handler ) {
// check if we have attachments
$files = $record->get( 'files' );
if ( empty( $files ) ) {
return;
}
// Store attachment in local var
foreach ( $files as $id => $files_array ) {
$this->attachments_array[] = $files_array['path'][0];
}
// if local var has attachments setup filter hook
if ( 0 < count( $this->attachments_array ) ) {
add_filter( 'wp_mail', [ $this, 'wp_mail' ] );
add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 );
}
}
public function remove_wp_mail_filter() {
if ( self::DELETE_ATTACHMENT_FROM_SERVER ) {
foreach ( $this->attachments_array as $uploaded_file ) {
unlink( $uploaded_file );
}
}
$this->attachments_array = [];
remove_filter( 'wp_mail', [ $this, 'wp_mail' ] );
}
public function wp_mail( $args ) {
$args['attachments'] = $this->attachments_array;
return $args;
}
}
new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
+1
+1
+1
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
I added this code to my function.php file. It does work, the attachments will appear as files in my mailbox. However, the attachments also appears in the confirmation mail to the submitter... how to disable this?
@joylauu It is easy to remove the link from the mail. Just add this method:
/**
* @param array $field Form field.
* @param Form_Record $instance An instance of the form record.
* @param Ajax_Handler $ajax_handler An instance of the ajax handler.
*/
public function remove_upload_field( $field, $instance, $ajax_handler ) {
$instance->remove_field( $field['id'] );
}
And this to construct:
add_action( 'elementor_pro/forms/process/upload', [ $this, 'remove_upload_field' ], 11, 3 );
Full-Class:
use ElementorPro\Modules\Forms\Classes\Ajax_Handler;
use ElementorPro\Modules\Forms\Classes\Form_Record;
/**
* Class Elementor_Form_Email_Attachments
*
* Send Elementor Form upload field as attachments to email
*/
class Elementor_Form_Email_Attachments {
// Set to true if you want the files to be removed from
// the server after they are sent by email
const DELETE_ATTACHMENT_FROM_SERVER = true;
public $attachments_array = [];
public function __construct() {
add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 );
add_action( 'elementor_pro/forms/process/upload', [ $this, 'remove_upload_field' ], 11, 3 );
}
/**
* @param \ElementorPro\Modules\Forms\Classes\Form_Record $record
* @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler
*/
public function init_form_email_attachments( $record, $ajax_handler ) {
// check if we have attachments
$files = $record->get( 'files' );
if ( empty( $files ) ) {
return;
}
// Store attachment in local var
foreach ( $files as $id => $files_array ) {
$this->attachments_array[] = $files_array['path'][0];
}
// if local var has attachments setup filter hook
if ( 0 < count( $this->attachments_array ) ) {
add_filter( 'wp_mail', [ $this, 'wp_mail' ] );
add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 );
}
}
public function remove_wp_mail_filter() {
if ( self::DELETE_ATTACHMENT_FROM_SERVER ) {
foreach ( $this->attachments_array as $uploaded_file ) {
unlink( $uploaded_file );
}
}
$this->attachments_array = [];
remove_filter( 'wp_mail', [ $this, 'wp_mail' ] );
}
public function wp_mail( $args ) {
$args['attachments'] = $this->attachments_array;
return $args;
}
/**
* @param array $field Form field.
* @param Form_Record $instance An instance of the form record.
* @param Ajax_Handler $ajax_handler An instance of the ajax handler.
*/
public function remove_upload_field( $field, $instance, $ajax_handler ) {
$instance->remove_field( $field['id'] );
}
}
@crazypsycho Does your code really remove attachment for email2 recipient? We just need to Elementor won't send attachments to email2 who is usually sender of form.
I saw this code posted to another user with my same issue but It's not working. I need to keep the original user file upload name. I'm not saving it to my server so it dupes don't matter and I'm only accepting docx, doc and pdf with captcha so I'm not worried about the other issues. It's imperative that I have the original file name
/**
@param callable|null $unique_filename_callback Callback function that generates the unique file name. */ add_filter( 'wp_unique_filename', function( $filename, $ext, $dir, $unique_filename_callback ) { static $file_count = 0; //used to get the current file when multiple uploads in a form // first make sure its an upload via elementor forms if ( false === strpos( $dir, '/elementor/forms' ) ) { return $filename; }
// get the original file name $path_parts = pathinfo( $_FILES['SET_FORM_FIELD_ID_HERE'][ $filename ] ); // Bump counter for next file $file_count++; // Return your desired file name (original-unique_suffix.extension) return $path_parts['filename'] . '-' . $filename;
}, 10, 4 );
+1 !!!
+1
+1
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
It does not work with multiple files upload. Only 1 attached to email while the rest left on server. Anyone else got same issue?
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
Works fine, but i have same problem like @david-strejc . The attachments also appears in the confirmation mail (mail2) to the submitter... how to disable this?
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
It does not work with multiple files upload. Only 1 attached to email while the rest left on server. Anyone else got same issue?
@ewallz I found out the solution, I was also having same problem. Actually code here was only setting value to starting index i.e. [0] only .... bug: $this->attachments_array[] = $files_array['path'][0]; Now upto 20 files can be attached 😄 Solved Complete Code:
/**
* Class Elementor_Form_Email_Attachments
*
* Send Elementor Form upload field as attachments to email
*/
class Elementor_Form_Email_Attachments {
// Set to true if you want the files to be removed from
// the server after they are sent by email
const DELETE_ATTACHMENT_FROM_SERVER = false;
public $attachments_array = [];
public function __construct() {
add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 );
}
/**
* @param \ElementorPro\Modules\Forms\Classes\Form_Record $record
* @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler
*/
public function init_form_email_attachments( $record, $ajax_handler ) {
// check if we have attachments
$files = $record->get( 'files' );
if ( empty( $files ) ) {
return;
}
// Store attachment in local var
//
//
foreach ( $files as $id => $files_array ){
/* New Fix For multiple files */
$len = 20;
for($i = 0; $i < $len; $i++) {
$this->attachments_array[] = $files_array['path'][$i];
}
}
// if local var has attachments setup filter hook
if ( 0 < count( $this->attachments_array ) ) {
add_filter( 'wp_mail', [ $this, 'wp_mail' ] );
add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 );
}
}
public function remove_wp_mail_filter() {
if ( self::DELETE_ATTACHMENT_FROM_SERVER ) {
foreach ( $this->attachments_array as $uploaded_file ) {
unlink( $uploaded_file );
}
}
$this->attachments_array = [];
remove_filter( 'wp_mail', [ $this, 'wp_mail' ] );
}
public function wp_mail( $args ) {
$args['attachments'] = $this->attachments_array;
return $args;
}
}
new Elementor_Form_Email_Attachments();
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
I added this code to my function.php file. It does work, the attachments will appear as files in my mailbox. However, the attachments also appears in the confirmation mail to the submitter... how to disable this?
@joylauu @david-strejc @krassomatiker
I encountered the exact problem.. I did this to solve the issue.. replace the class' wp_mail function with the one below and put "[elementor_form_no_attachment]" anywhere in Email2's message field
public function wp_mail( $args ) {
// check for no attachment flag
$no_attachments = strpos($args['message'], '[elementor_form_no_attachment]');
if ( FALSE !== $no_attachments ) {
// remove the flag from the message
$args['message'] = str_replace('[elementor_form_no_attachment]', '', $args['message']);
} else {
// attach files instead
$args['attachments'] = $this->attachments_array;
}
return $args;
}
It is essential to have a native function in the Elementor to send the file as an attachment! Please do that asap. Thanks
I would like to see attachments sent via email attachments. At the moment I am using Contact Form 7 because of this feature.
I am using Elementor for a recruitment website. The CRM behind it will only accept resumes from a mailform that sends them as attachment to their mailbox. Can you please help us with this feature? It is really not that difficult to supply this feature I think! Greetings!
+1, must have feature in 2020 and 2019
+1
I now have clients asking me for this feature
+1
Really needed this feature. Retrieving each attachment and matching it to the email is such a hassle.
+1
+1
+100
Really need to retain the original filenames - I can't understand why this isn't part of the native Elementor forms.
I need to add attachments to confirmation emails, where the users sign up for ebooks... The 'Redirect' action after submit eleminates code needed to fix Contact7, but now I'll need to add code to fix Elementor Pro to send the attachment with the email... Probably will wait until you add this, so please do so as soon as possible.
Thanks.
+1
+1 please
+1
+1
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
It does not work with multiple files upload. Only 1 attached to email while the rest left on server. Anyone else got same issue?
@ewallz I found out the solution, I was also having same problem. Actually code here was only setting value to starting index i.e. [0] only .... bug: $this->attachments_array[] = $files_array['path'][0]; Now upto 20 files can be attached 😄 Solved Complete Code:
/** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var // // foreach ( $files as $id => $files_array ){ /* New Fix For multiple files */ $len = 20; for($i = 0; $i < $len; $i++) { $this->attachments_array[] = $files_array['path'][$i]; } } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Doesn't this work for all forms on the website? As in my case, it worked on one form, but when I created another form, files uploaded through it are again uploaded to the server.
So glad I am not the only one who wants this!
This needs to be a feature ASAP. And since the files stay on my server from what it seems with no auto delete function I will have to use Contact Form 7 instead of elementor. I really wanted to use elementors forms since the steps feature is nice but I guess even in 2 years later I cant
Edit- CF7 with conditional logic is the way to go for a good contact form.
+1
+1 clients need this. Make it happen ya wonderful developers ♥
Adding this version of the class which lets you remove the files from the server after they are sent.
<?php /** * Class Elementor_Form_Email_Attachments * * Send Elementor Form upload field as attachments to email */ class Elementor_Form_Email_Attachments { // Set to true if you want the files to be removed from // the server after they are sent by email const DELETE_ATTACHMENT_FROM_SERVER = false; public $attachments_array = []; public function __construct() { add_action( 'elementor_pro/forms/process', [ $this, 'init_form_email_attachments' ], 11, 2 ); } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function init_form_email_attachments( $record, $ajax_handler ) { // check if we have attachments $files = $record->get( 'files' ); if ( empty( $files ) ) { return; } // Store attachment in local var foreach ( $files as $id => $files_array ) { $this->attachments_array[] = $files_array['path'][0]; } // if local var has attachments setup filter hook if ( 0 < count( $this->attachments_array ) ) { add_filter( 'wp_mail', [ $this, 'wp_mail' ] ); add_action( 'elementor_pro/forms/new_record', [ $this, 'remove_wp_mail_filter' ], 5 ); } } public function remove_wp_mail_filter() { if ( self::DELETE_ATTACHMENT_FROM_SERVER ) { foreach ( $this->attachments_array as $uploaded_file ) { unlink( $uploaded_file ); } } $this->attachments_array = []; remove_filter( 'wp_mail', [ $this, 'wp_mail' ] ); } public function wp_mail( $args ) { $args['attachments'] = $this->attachments_array; return $args; } } new Elementor_Form_Email_Attachments();
Just set the
const DELETE_ATTACHMENT_FROM_SERVER = false;
to
const DELETE_ATTACHMENT_FROM_SERVER = true;
Does this still work on version 3.03? with wordpress 5.5
This issue has been open for over two years. There have been so many releases in that time period. Why has this not been integrated yet? It's clearly been requested in multiple other issues that have been closed and merged into this one. It's extremely problematic to leave file uploads permanently on the server, especially in the post-GDPR world, that's a significant liability. It should just be an option in the form setup, whether or not we want to store uploads as links or attachments, and whether or not to immediately delete the uploads. Please add this ASAP.
+1 at least drop an explanation here why it can't be implemented or anything.
This issue has been open for over two years. There have been so many releases in that time period. Why has this not been integrated yet? It's clearly been requested in multiple other issues that have been closed and merged into this one. It's extremely problematic to leave file uploads permanently on the server, especially in the post-GDPR world, that's a significant liability. It should just be an option in the form setup, whether or not we want to store uploads as links or attachments, and whether or not to immediately delete the uploads. Please add this ASAP.
I forgot to mention, I tried it and it does work. Still would love to see it implemented
Prerequisites
Wordpress & Elementor Pro
What problem is your feature request going to solve? Please describe. Elementor Contact Form email attachments should not go to ftp drive and sent as a link. It is annoying and takes too long to delete.
Describe the solution you'd like We would suggest Elementor Email Forms should be sent as E-Mail Attachments instead of saving to ftp server as a link. It is very annoying and counter intuitive for us to have to go to the ftp drive to retrieve/delete images a customer sends to us via form attachments. It would be best if either they can be just sent as an "attachment" or a folder you could create in wp-admin > elementor > email attachments. Either way would be better than the system now. But a regular old fashioned email attachment is preferred.
Describe alternatives you've considered Above is all
Additional context None