elementor / elementor

The most advanced frontend drag & drop page builder. Create high-end, pixel perfect websites at record speeds. Any theme, any page, any design.
https://elementor.com/
GNU General Public License v3.0
6.45k stars 1.4k forks source link

✅ 🔗 🚀 Feature Request: Send E-Mail Form Attachments as Regular E-Mail Attachments instead of a link that is saved in the ftp server - [ED-2192] #4868

Closed smile00000 closed 4 months ago

smile00000 commented 5 years ago

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

black-eye commented 5 years ago

+1

bainternet commented 5 years ago

@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.

smile00000 commented 5 years ago

Thank you for the code, do we put this in the CSS box of the elementor widget?

smile00000 commented 5 years ago

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?

bainternet commented 5 years ago

It's here and labeled so no need to keep it open if we get many new requests then ....

thanks.

sugarchrist commented 5 years ago

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

lauranunez commented 5 years ago

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!

parfilov commented 5 years ago

+1

RUSxDeviL1979 commented 5 years ago
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.

sugarchrist commented 5 years ago

Hi bainternet, Does this mean that it has been resolved? Thank you

RUSxDeviL1979 commented 5 years ago

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

RUSxDeviL1979 commented 5 years ago

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 .

-- Алексей Теняков

bainternet commented 5 years ago

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;
E-Markers commented 5 years ago

+1

esaygo commented 5 years ago

+1

MAthez commented 5 years ago

+1

joylauu commented 5 years ago

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?

crazypsycho commented 4 years ago

@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'] );
    }
}
david-strejc commented 4 years ago

@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.

863chick commented 4 years ago

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

/**

}, 10, 4 );

patrickwlm commented 4 years ago

+1 !!!

fxaviers commented 4 years ago

+1

mskks64 commented 4 years ago

+1

ewallz commented 4 years ago

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?

krassomatiker commented 4 years ago

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?

shafqatkhan60 commented 4 years ago

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();
darrillouie commented 4 years ago

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;
}
acornavi commented 4 years ago

It is essential to have a native function in the Elementor to send the file as an attachment! Please do that asap. Thanks

am683 commented 4 years ago

I would like to see attachments sent via email attachments. At the moment I am using Contact Form 7 because of this feature.

RudiVL commented 4 years ago

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!

CoSciBlog commented 4 years ago

+1, must have feature in 2020 and 2019

simonclay commented 4 years ago

+1

I now have clients asking me for this feature

alexloganlee commented 4 years ago

+1

Really needed this feature. Retrieving each attachment and matching it to the email is such a hassle.

davidamarek commented 4 years ago

+1

deac83 commented 4 years ago

+1

erezel commented 4 years ago

+100

davidamarek commented 4 years ago

Really need to retain the original filenames - I can't understand why this isn't part of the native Elementor forms.

maskeny commented 4 years ago

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.

rkhyd commented 4 years ago

+1

catmur-neame commented 4 years ago

+1 please

Dkogan90 commented 4 years ago

+1

MtoMCreation commented 4 years ago

+1

sss9212 commented 3 years ago

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.

asimcard commented 3 years ago

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.

thecreativeoffices commented 3 years ago

+1

AndersJpg commented 3 years ago

+1 clients need this. Make it happen ya wonderful developers ♥

itrejomx commented 3 years ago

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

blakmarkit commented 3 years ago

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.

WeArtStudioNL commented 3 years ago

+1 at least drop an explanation here why it can't be implemented or anything.

itrejomx commented 3 years ago

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