diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index aa35fa988d1..c3139bb3c78 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -844,8 +844,9 @@ class FormMail extends Form
foreach ($listofpaths as $key => $val) {
$relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
- if ($conf->entity > 1) {
- $relativepathtofile = str_replace('/'.$conf->entity.'/', '/', $relativepathtofile);
+ $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity);
+ if ($entity > 1) {
+ $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile);
}
// Try to extract data from full path
$formfile_params = array();
@@ -855,7 +856,7 @@ class FormMail extends Form
// Preview of attachment
$out .= img_mime($listofnames[$key]).' '.$listofnames[$key];
- $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
+ $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity));
if (!$this->withfilereadonly) {
$out .= ' ';
//$out.= ' '.img_delete($langs->trans("Delete").'';
diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php
index 039f4e2a96a..9f8b7ab95b7 100644
--- a/htdocs/core/tpl/card_presend.tpl.php
+++ b/htdocs/core/tpl/card_presend.tpl.php
@@ -387,6 +387,7 @@ if ($action == 'presend') {
$formmail->param['id'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"].'?id='.$object->id;
$formmail->param['fileinit'] = array($file);
+ $formmail->param['object_entity'] = $object->entity;
// Show form
print $formmail->get_form();