From 5e09c090a23853cf3f174b2f6459520668e0d039 Mon Sep 17 00:00:00 2001 From: yehudah Date: Mon, 20 Jan 2020 21:09:16 +0000 Subject: fix duplicate in sendgrid and duplicate failed log --- Postman/Phpmailer/PostsmtpMailer.php | 2 -- Postman/Postman-Mail/PostmanSendGridMailEngine.php | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Postman/Phpmailer/PostsmtpMailer.php b/Postman/Phpmailer/PostsmtpMailer.php index c86a0a0..eb0246f 100644 --- a/Postman/Phpmailer/PostsmtpMailer.php +++ b/Postman/Phpmailer/PostsmtpMailer.php @@ -125,8 +125,6 @@ class PostsmtpMailer extends PHPMailer { $this->mailHeader = ''; - do_action( 'post_smtp_on_failed', $log, $postmanMessage, $this->transcript, $transport, $exc->getMessage() ); - $this->setError($exc->getMessage()); if ($this->exceptions) { throw $exc; 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); -- cgit v1.2.3