@Nikolajpetersen the original was this:

```php
$to = array();
foreach ($message->getTo() as $address) {
    $to[] = $address->toString();
}

$parameters['to'] = implode(',', $to);
```

And this is now this:

```php
$to = array();
foreach ($message->getTo() as $address) {
    $to[] = $address->toString();
}

if ($message instanceof MailgunMessage && count($message->getRecipientVariables())) {
    $parameters['to'] = $to;
    $parameters['recipient-variables'] = json_encode($message->getRecipientVariables());
} else {
    $parameters['to'] = implode(',', $to);
}
```

And as I see it now @bakura10 argues it should look like this:

```php
$to = array();
foreach ($message->getTo() as $address) {
    $to[] = $address->toString();
}

if ($message instanceof MailgunMessage && count($message->getRecipientVariables())) {
    $parameters['to'] = implode(',', $to);
    $parameters['recipient-variables'] = json_encode($message->getRecipientVariables());
} else {
    $parameters['to'] = implode(',', $to);
}
```

Which could be refactored to this:
```php
$to = array();
foreach ($message->getTo() as $address) {
    $to[] = $address->toString();
}

$parameters['to'] = implode(',', $to);

if ($message instanceof MailgunMessage && count($message->getRecipientVariables())) {
    $parameters['recipient-variables'] = json_encode($message->getRecipientVariables());
}
```

I.e.: the content of `$parameters['to']` shouldn't change, as it should still be a comma separated list of email addresses. Now, in the case if recipient variables are set, it is changed into an array instead of a comma separated string.

With this check separated from the `$parameters['to']`, you could even set last `if` block inside the `if ($message instanceof MailgunMessage)` [located here](https://github.com/Nikolajpetersen/SlmMail/blob/94ce06cda6d5244fd39899e3da9002b2d29a6cb7/src/SlmMail/Service/MailgunService.php#L140).

Michael, please correct me if I'm wrong here.