diff options
-rw-r--r-- | lib/SparkPost/Transmission.php | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php index a356c9b..7d45928 100644 --- a/lib/SparkPost/Transmission.php +++ b/lib/SparkPost/Transmission.php @@ -33,12 +33,14 @@ class Transmission extends Resource } //loop through all BCC recipients - foreach ($bccList as $bccRecipient) { - $newRecipient = [ - 'address' => $bccRecipient['address'], - 'header_to' => $originalRecipient, - ]; - array_push($recipientsList, $newRecipient); + if(isset($bccList)){ + foreach ($bccList as $bccRecipient) { + $newRecipient = [ + 'address' => $bccRecipient['address'], + 'header_to' => $originalRecipient, + ]; + array_push($recipientsList, $newRecipient); + } } //Delete the BCC object/array @@ -62,24 +64,27 @@ class Transmission extends Resource $originalRecipient = '<' . $modifiedPayload['recipients'][0]['address'] . '>'; } + + if(isset($ccList)){ + foreach ($ccList as $ccRecipient) { + $newRecipient = [ + 'address' => $ccRecipient['address'], + 'header_to' => $originalRecipient, + ]; - foreach ($ccList as $ccRecipient) { - $newRecipient = [ - 'address' => $ccRecipient['address'], - 'header_to' => $originalRecipient, - ]; - - //if name exists, then use "Name" <Email> format. Otherwise, just email will suffice. - if(isset($ccRecipient['name'])) { - $ccCustomHeadersList = $ccCustomHeadersList . ' "' . $ccRecipient['name'] - . '" <' . $ccRecipient['address'] . '>,'; - } else { - $ccCustomHeadersList = $ccCustomHeadersList . ' ' . $ccRecipient['address']; - } - - array_push($recipientsList, $newRecipient); + //if name exists, then use "Name" <Email> format. Otherwise, just email will suffice. + if(isset($ccRecipient['name'])) { + $ccCustomHeadersList = $ccCustomHeadersList . ' "' . $ccRecipient['name'] + . '" <' . $ccRecipient['address'] . '>,'; + } else { + $ccCustomHeadersList = $ccCustomHeadersList . ' ' . $ccRecipient['address']; + } + + array_push($recipientsList, $newRecipient); + } } + //Creates customHeaders and adds CSV list of CC emails $customHeaders = array("CC" => $ccCustomHeadersList); $modifiedPayload['customHeaders'] = $customHeaders; |