diff options
author | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2020-01-20 21:09:16 +0000 |
---|---|---|
committer | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2020-01-20 21:09:16 +0000 |
commit | 5e09c090a23853cf3f174b2f6459520668e0d039 (patch) | |
tree | d4d8bcc1f814aa54d759ebca3ac13fcb55589be6 /Postman/Postman-Mail | |
parent | 8c9462e6ab86a80ad79ea478601a38c76915548e (diff) | |
download | Post-SMTP-5e09c090a23853cf3f174b2f6459520668e0d039.zip |
fix duplicate in sendgrid and duplicate failed log
Diffstat (limited to 'Postman/Postman-Mail')
-rw-r--r-- | Postman/Postman-Mail/PostmanSendGridMailEngine.php | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Postman/Postman-Mail/PostmanSendGridMailEngine.php b/Postman/Postman-Mail/PostmanSendGridMailEngine.php index 2ffb8e2..336bd89 100644 --- a/Postman/Postman-Mail/PostmanSendGridMailEngine.php +++ b/Postman/Postman-Mail/PostmanSendGridMailEngine.php @@ -57,9 +57,14 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) { // now log it $sender->log( $this->logger, 'From' ); + $duplicates = array(); + // add the to recipients foreach ( ( array ) $message->getToRecipients() as $recipient ) { - $emails[] = new \SendGrid\Mail\To($recipient->getEmail(), $recipient->getName() ); + if ( ! in_array( $recipient->getEmail(), $duplicates ) ) { + $emails[] = new \SendGrid\Mail\To( $recipient->getEmail(), $recipient->getName() ); + $duplicates[] = $recipient->getEmail(); + } } $email->addTos( $emails ); @@ -111,16 +116,22 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) { // add the cc recipients $ccEmails = array(); foreach ( ( array ) $message->getCcRecipients() as $recipient ) { - $recipient->log( $this->logger, 'Cc' ); - $ccEmails[] = new \SendGrid\Mail\Cc( $recipient->getEmail(), $recipient->getName() ); + if ( ! in_array( $recipient->getEmail(), $duplicates ) ) { + $recipient->log($this->logger, 'Cc'); + $ccEmails[] = new \SendGrid\Mail\Cc($recipient->getEmail(), $recipient->getName()); + $duplicates[] = $recipient->getEmail(); + } } $email->addCcs($ccEmails); // add the bcc recipients $bccEmails = array(); foreach ( ( array ) $message->getBccRecipients() as $recipient ) { - $recipient->log($this->logger, 'Bcc'); - $bccEmails[] = new \SendGrid\Mail\Bcc( $recipient->getEmail(), $recipient->getName() ); + if ( ! in_array( $recipient->getEmail(), $duplicates ) ) { + $recipient->log($this->logger, 'Bcc'); + $bccEmails[] = new \SendGrid\Mail\Bcc($recipient->getEmail(), $recipient->getName()); + $duplicates[] = $recipient->getEmail(); + } } $email->addBccs($bccEmails); |