From c5ec35bfe0d28b6891121565afe12cab63110b87 Mon Sep 17 00:00:00 2001 From: Xenomporio <> Date: Thu, 30 Jun 2022 12:31:39 +0200 Subject: [PATCH] sendmail function can now send to multiple recipients --- www/lib/class.erpapi.php | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index de42015f..15c43859 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -32456,7 +32456,7 @@ function ChargenMHDAuslagern($artikel, $menge, $lagerplatztyp, $lpid,$typ,$wert, function MailSendFinal($from,$from_name,$to,$to_name,$betreff,$text,$files="",$projekt="",$signature=true,$cc="",$bcc="", $system = false) { // keine leeren email versenden - if($text=="" && $betreff=="") return; + if($text=="" && $betreff=="") return; /* $isSystemTemplate = $system && is_file(dirname(__DIR__, 2) .'/classes/Modules/Company/templates/systemmail.tpl'); if($isSystemTemplate) { @@ -32468,8 +32468,6 @@ function MailSendFinal($from,$from_name,$to,$to_name,$betreff,$text,$files="",$p } $from_name = $this->ClearDataBeforeOutput($from_name); - $to_name = $this->ClearDataBeforeOutput($to_name); - $to_name = $this->ReadyForPDF($to_name); $from_name = $this->ReadyForPDF($from_name); $betreff = $this->ReadyForPDF($betreff); $text = $this->ReadyForPDF($text); @@ -32569,7 +32567,48 @@ function MailSendFinal($from,$from_name,$to,$to_name,$betreff,$text,$files="",$p if ($sysMailer !== null) { $recipients = []; - $recipients[] = new EmailRecipient($to, $to_name); + + // Prepare names and addresses + if (is_array($to)) { + foreach ($to as $item) { + $to_array[] = $item; + } + } else if (!empty($to)) { + foreach (explode(',',str_replace(" ","",$to)) as $item) { + $to_array[] = $item; + } + } + if (is_array($to_name)) { + foreach ($to_name as $item) { + $to_name_array[] = $item; + } + } else if (!empty($to_name)) { + foreach (explode(',',str_replace(" ","",$to_name)) as $item) { + $to_name_array[] = $item; + } + } + + // Fill empty names with address + + $number_of_names = empty($to_name_array)?0:count($to_name_array); + + if (count($to_array) > $number_of_names) { + $itemcount = 0; + foreach ($to_array as $item) { + $itemcount++; + if ($itemcount > $number_of_names) { + $to_name_array[] = $item; + } + } + } + + $to_combined_array = array_combine($to_array,$to_name_array); + + foreach ($to_combined_array as $key => $value) { + $value = $this->ClearDataBeforeOutput($value); + $value = $this->ReadyForPDF($value); + $recipients[] = new EmailRecipient($key, $value); + } $ccRecipients = []; if (is_array($cc)) {