This commit is contained in:
Florian HENRY 2022-10-10 15:00:51 +02:00
parent a780829a1b
commit fea1b2ef14

View File

@ -5526,7 +5526,7 @@ class Facture extends CommonInvoice
$sendContent = make_substitutions($content, $substitutionarray, $outputlangs, 1); $sendContent = make_substitutions($content, $substitutionarray, $outputlangs, 1);
// Recipient // Recipient
$to = ''; $to = array();
$res = $tmpinvoice->fetch_thirdparty(); $res = $tmpinvoice->fetch_thirdparty();
$recipient = $tmpinvoice->thirdparty; $recipient = $tmpinvoice->thirdparty;
if ($res > 0) { if ($res > 0) {
@ -5534,13 +5534,12 @@ class Facture extends CommonInvoice
if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
foreach ($tmparraycontact as $data_email) { foreach ($tmparraycontact as $data_email) {
if (!empty($data_email['email'])) { if (!empty($data_email['email'])) {
$to = $data_email['email']; $to[] = $data_email['firstname'] . ' '. $data_email['lastname']. '<'.$data_email['email'].'>';
break;
} }
} }
} }
if (empty($to) && !empty($recipient->email)) { if (empty($to) && !empty($recipient->email)) {
$to = $recipient->email; $to[] = $recipient->email;
} else { } else {
$errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user."; $errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user.";
$error++; $error++;
@ -5557,9 +5556,11 @@ class Facture extends CommonInvoice
$error++; $error++;
} }
if (!$error && $to) { if (!$error && !empty($to)) {
$this->db->begin(); $this->db->begin();
$to = implode(',', $to);
// Errors Recipient // Errors Recipient
$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;