diff --git a/lib/Mailer/Methods/MailPoet.php b/lib/Mailer/Methods/MailPoet.php index 83014fad17..6419d42f21 100644 --- a/lib/Mailer/Methods/MailPoet.php +++ b/lib/Mailer/Methods/MailPoet.php @@ -118,7 +118,7 @@ class MailPoet { return $body; } - private function composeBody($newsletter, $subscriber, $unsubscribeUrl, $meta) { + private function composeBody($newsletter, $subscriber, $unsubscribeUrl, $meta): array { $body = [ 'to' => ([ 'address' => $subscriber['email'], @@ -130,10 +130,12 @@ class MailPoet { ]), 'reply_to' => ([ 'address' => $this->replyTo['reply_to_email'], - 'name' => $this->replyTo['reply_to_name'], ]), 'subject' => $newsletter['subject'], ]; + if (!empty($this->replyTo['reply_to_name'])) { + $body['reply_to']['name'] = $this->replyTo['reply_to_name']; + } if (!empty($newsletter['body']['html'])) { $body['html'] = $newsletter['body']['html']; } diff --git a/tests/integration/Mailer/Methods/MailPoetAPITest.php b/tests/integration/Mailer/Methods/MailPoetAPITest.php index e62b525e21..37dae3d588 100644 --- a/tests/integration/Mailer/Methods/MailPoetAPITest.php +++ b/tests/integration/Mailer/Methods/MailPoetAPITest.php @@ -75,6 +75,24 @@ class MailPoetAPITest extends \MailPoetTest { expect($body[0]['text'])->equals($this->newsletter['body']['text']); } + public function testItRemovesReplyToNameIfEmpty() { + $replyTo = [ + 'reply_to_email' => 'reply-to@mailpoet.com', + 'reply_to_name_email' => '', + ]; + $mailer = new MailPoet( + $this->settings['api_key'], + $this->sender, + $replyTo, + new MailPoetMapper(), + $this->makeEmpty(AuthorizedEmailsController::class) + ); + $body = $mailer->getBody($this->newsletter, $this->subscriber); + expect($body[0]['reply_to'])->equals([ + 'address' => 'reply-to@mailpoet.com', + ]); + } + public function testItCanGenerateBodyForMultipleMessages() { $newsletters = array_fill(0, 10, $this->newsletter); $subscribers = array_fill(0, 10, $this->subscriber);