Buy Now
Sign in

FAQ search

How can I attach files from my server to an email in CFv5

Published: Thursday, 05 June 2014 15:39

Please drag a Custom Code action before the Email action and add code like this:

$path = JPATH_SITE.'/components/com_chronoforms5/uploads/folder_name/';
$form->files['field_name']['path'] = $path.'file_name.jpg';

Change the folder path, the file name and the 'field_name' to suit your needs.

Now, in your Email action "Attachments fields names" setting, just enter field_name (with no quotes or brackets).

Adding multiple files

If you have a list of files to add you can extend the code like this

$files = array(
$path = JPATH_SITE.'/components/com_chronoforms5/uploads/folder_name/';
foreach ( $files as $k => $f ) {
  $form->files['files_to_send'][$k]['path'] = $path.$f;

Then add files_to send in the Email action Attachements box.

You can modify this example to create the files array based on user inputs - for example to match a set of checkboxes that have been submitted.