diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 640355c1295..de93ee8f66d 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -881,8 +881,12 @@ class FormMail extends Form $out.= ''; + if (GETPOSTISSET('sendmail')) + { + $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); + } // If a template was selected, we use setup of template to define if join file checkbox is selected or not. - if (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) + elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); } @@ -895,7 +899,7 @@ class FormMail extends Form } if ($this->withmaindocfile == -1) { - $out.=''; + $out.=''; } $out.=' '.$langs->trans("JoinMainDoc").'.
'; } diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index d46e27e28af..a66e9ba270e 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -41,11 +41,12 @@ if ($massaction == 'presend') { $langs->load("mails"); + $listofselectedid = array(); + $listofselectedthirdparties = array(); + $listofselectedref = array(); + if (! GETPOST('cancel', 'alpha')) { - $listofselectedid = array(); - $listofselectedthirdparties = array(); - $listofselectedref = array(); foreach ($arrayofselected as $toselectid) { $result = $objecttmp->fetch($toselectid); @@ -110,8 +111,8 @@ if ($massaction == 'presend') } else { $formmail->withtoreadonly = 1; } - - $formmail->withoptiononeemailperrecipient = empty($liste)?0:((GETPOST('oneemailperrecipient')=='on')?1:-1); + + $formmail->withoptiononeemailperrecipient = (count($listofselectedref) == 1 || empty($liste))? 0 : ((GETPOST('oneemailperrecipient')=='on')?1:-1); $formmail->withto = empty($liste)?(GETPOST('sendto','alpha')?GETPOST('sendto','alpha'):array()):$liste; $formmail->withtofree = empty($liste)?1:0; $formmail->withtocc = 1;