FIX Sending email to mass actions send same email on same customer

This commit is contained in:
Laurent Destailleur 2019-05-08 19:07:12 +02:00
parent b5d8bc732d
commit f6de2d091d
3 changed files with 10 additions and 10 deletions

View File

@ -354,8 +354,6 @@ $facturestatic=new Facture($db);
$formcompany=new FormCompany($db);
$thirdpartystatic=new Societe($db);
// llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
$sql = 'SELECT';
if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
$sql.= ' f.rowid as id, f.facnumber as ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';

View File

@ -365,8 +365,8 @@ if (! $error && $massaction == 'confirm_presend')
$looparray[0]=$objectforloop;
}
//var_dump($looparray);exit;
dol_syslog("We have set an array of ".count($looparray)." emails to send");
dol_syslog("We have set an array of ".count($looparray)." emails to send. oneemailperrecipient=".$oneemailperrecipient);
//var_dump($oneemailperrecipient); var_dump($listofqualifiedobj); var_dump($listofqualifiedref);
foreach ($looparray as $objectid => $objecttmp) // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per object
{
// Make substitution in email content
@ -387,8 +387,8 @@ if (! $error && $massaction == 'confirm_presend')
complete_substitutions_array($substitutionarray, $langs, $objecttmp, $parameters);
$subject=make_substitutions($subject, $substitutionarray);
$message=make_substitutions($message, $substitutionarray);
$subjectreplaced=make_substitutions($subject, $substitutionarray);
$messagereplaced=make_substitutions($message, $substitutionarray);
$filepath = $attachedfiles['paths'];
$filename = $attachedfiles['names'];
@ -416,10 +416,11 @@ if (! $error && $massaction == 'confirm_presend')
}
//var_dump($filepath);
//var_dump($trackid);exit;
//var_dump($subjectreplaced);
// Send mail (substitutionarray must be done just before this)
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
$mailfile = new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid);
if ($mailfile->error)
{
$resaction.='<div class="error">'.$mailfile->error.'</div>';
@ -451,9 +452,9 @@ if (! $error && $massaction == 'confirm_presend')
if ($message)
{
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subjectreplaced);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
$actionmsg = dol_concatdesc($actionmsg, $message);
$actionmsg = dol_concatdesc($actionmsg, $messagereplaced);
}
$actionmsg2='';

View File

@ -112,7 +112,8 @@ if ($massaction == 'presend')
$formmail->withtoreadonly = 1;
}
$formmail->withoptiononeemailperrecipient = (count($listofselectedref) == 1 || empty($liste))? 0 : ((GETPOST('oneemailperrecipient')=='on')?1:-1);
$formmail->withoptiononeemailperrecipient = ((count($listofselectedref) == 1 && count(reset($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;