From 49bfcfd66cd30ce182aa463a290b0d3fbae92fbe Mon Sep 17 00:00:00 2001 From: Aingel Date: Sat, 16 Oct 2021 02:45:34 +0800 Subject: [PATCH] Update Mail.php Ensure the uniqueness of email addresses when adding recipients in all emailTypes. Mitigation for error: "Each email address in the personalization block should be unique between to, cc, and bcc" --- lib/mail/Mail.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/mail/Mail.php b/lib/mail/Mail.php index 13cff7e94..2bbc9368e 100644 --- a/lib/mail/Mail.php +++ b/lib/mail/Mail.php @@ -81,6 +81,13 @@ class Mail implements \JsonSerializable /** @var $personalization Personalization[] Messages and their metadata */ private $personalization; + /** @var $emailRecipients monitors unique email addresses in each emailType */ + private $emailRecipients = array( + 'To' => array(), + 'Cc' => array(), + 'Bcc' => array() + ); + /** * If passing parameters into this constructor, include $from, $to, $subject, * $plainTextContent, $htmlContent and $globalSubstitutions at a minimum. @@ -198,18 +205,20 @@ private function addRecipientEmail( && $emailType === 'To' && $email->isPersonalized()) { $personalization = new Personalization(); } - - $personalization = $this->getPersonalization($personalizationIndex, $personalization); - $personalization->$personalizationFunctionCall($email); - - if ($subs = $email->getSubstitutions()) { - foreach ($subs as $key => $value) { - $personalization->addSubstitution($key, $value); + if(!in_array($email->getEmailAddress(),$this->emailRecipients[$emailType])){ + $this->emailRecipients[$emailType][] = $email->getEmailAddress(); + $personalization = $this->getPersonalization($personalizationIndex, $personalization); + $personalization->$personalizationFunctionCall($email); + + if ($subs = $email->getSubstitutions()) { + foreach ($subs as $key => $value) { + $personalization->addSubstitution($key, $value); + } } - } - if ($email->getSubject()) { - $personalization->setSubject($email->getSubject()); + if ($email->getSubject()) { + $personalization->setSubject($email->getSubject()); + } } }