FAQs

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

Written

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

<?php
$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


<?php
$files = array(
  'file_name_a.png',
  'file_name_b.png'
);
$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.