diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 4f39ce3..6212c47 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -97,7 +97,7 @@ class BatchMessage extends MessageBuilder if (array_key_exists($headerName, $this->counters['recipients'])) { $this->counters['recipients'][$headerName] += 1; - if (!array_key_exists('id', $variables)) { + if (is_array($variables) && !array_key_exists('id', $variables)) { $variables['id'] = $this->counters['recipients'][$headerName]; } } diff --git a/tests/Messages/BatchMessageTest.php b/tests/Messages/BatchMessageTest.php index 6668b7b..97a606c 100644 --- a/tests/Messages/BatchMessageTest.php +++ b/tests/Messages/BatchMessageTest.php @@ -41,6 +41,20 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase $this->assertEquals(1, $array['recipients']['to']); } + public function testAddRecipientWithoutFirstAndLastName() + { + $message = $this->client->BatchMessage($this->sampleDomain); + $message->addToRecipient('test@samples.mailgun.org', 'this-is-not-an-array'); + $messageObj = $message->getMessage(); + $this->assertEquals(['to' => ['test@samples.mailgun.org']], $messageObj); + + $reflectionClass = new \ReflectionClass(get_class($message)); + $property = $reflectionClass->getProperty('counters'); + $property->setAccessible(true); + $array = $property->getValue($message); + $this->assertEquals(1, $array['recipients']['to']); + } + public function testRecipientVariablesOnTo() { $message = $this->client->BatchMessage($this->sampleDomain);