protected function format(MessageInterface $message)
    {
        $from = $this->normalizeIdentity($message->getFrom());

        $parameters = [
            'options' => [
                'transactional' => $this->transactional,
            ],
            'content' => [
                'from' => [
                    'name'  => $from->getName(),
                    'email' => $from->getEmail(),
                ],
                'subject' => $message->getSubject(),
                'text'    => $message->getText(),
                'html'    => $message->getHtml(),
            ],
        ];

        if ($message->getReplyTo()) {
            $parameters['content']['reply_to'] = $message->getReplyTo();
        }

        if (count($message->getHeaders())) {
            $parameters['content']['headers'] = $message->getHeaders();
        }

        if ($message instanceof AttachmentsAwareInterface) {
            foreach ($message->getAttachments() as $attachment) {
                $inline = $attachment->getId() !== null;
                $parameters['content'][$inline ? 'inline_images' : 'attachments'][] = [
                    'type' => $attachment->getType(),
                    'name' => $inline ? $attachment->getId() : $attachment->getName(),
                    'data' => base64_encode($this->getAttachmentContent($attachment)),
                ];
            }
        }

        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
            if (count($metadata)) {
                $parameters['metadata'] = $metadata;
            }
        }

        $tags = [];
        if ($message instanceof TaggableInterface) {
            $tags = (array) $message->getTag();
        }

        $normalizedTo = $this->normalizeIdentities($message->getTo());
        $normalizedCc = $this->normalizeIdentities($message->getCc());
        $normalizedBcc = $this->normalizeIdentities($message->getBcc());
        $toIdentityString = IdentityUtils::buildIdentityString($normalizedTo);

        /** @var \Stampie\Identity[] $merged */
        $merged = array_merge($normalizedTo, $normalizedCc, $normalizedBcc);
        foreach ($merged as $recipient) {
            /*
             * The reason we are specifying header_to is so that each recipient can see *everybody* who received
             * the email. Without it, each recipient will only see their email in the To field.
             *
             * IMPORTANT: Do not specify address.name!
             * If given, SparkPost will try to wrap the entire header_to value, mangling it in the process.
             */

            $parameters['recipients'][] = [
                'address' => [
                    'email'     => $recipient->getEmail(),
                    'header_to' => $toIdentityString,
                ],
                'tags' => $tags,
            ];
        }

        if (count($normalizedCc)) {
            $parameters['content']['headers']['CC'] = IdentityUtils::buildIdentityString($normalizedCc);
        }

        return json_encode($parameters);
    }
protected function format(MessageInterface $message)
    {
        $from = $this->normalizeIdentity($message->getFrom());

        $parameters = [
            'options' => [
                'transactional' => $this->transactional,
            ],
            'content' => [
                'from' => [
                    'name'  => $from->getName(),
                    'email' => $from->getEmail(),
                ],
                'subject' => $message->getSubject(),
                'text'    => $message->getText(),
                'html'    => $message->getHtml(),
            ],
        ];

        if ($message->getReplyTo()) {
            $parameters['content']['reply_to'] = $message->getReplyTo();
        }

        if (count($message->getHeaders())) {
            $parameters['content']['headers'] = $message->getHeaders();
        }

        if ($message instanceof AttachmentsAwareInterface) {
            foreach ($message->getAttachments() as $attachment) {
                $inline = $attachment->getId() !== null;
                $parameters['content'][$inline ? 'inline_images' : 'attachments'][] = [
                    'type' => $attachment->getType(),
                    'name' => $inline ? $attachment->getId() : $attachment->getName(),
                    'data' => base64_encode($this->getAttachmentContent($attachment)),
                ];
            }
        }

        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
            if (count($metadata)) {
                $parameters['metadata'] = $metadata;
            }
        }

        $tags = [];
        if ($message instanceof TaggableInterface) {
            $tags = (array) $message->getTag();
        }

        $normalizedTo = $this->normalizeIdentities($message->getTo());
        $normalizedCc = $this->normalizeIdentities($message->getCc());
        $normalizedBcc = $this->normalizeIdentities($message->getBcc());
        $toIdentityString = IdentityUtils::buildIdentityString($normalizedTo);

        
        $merged = array_merge($normalizedTo, $normalizedCc, $normalizedBcc);
        foreach ($merged as $recipient) {
            

            $parameters['recipients'][] = [
                'address' => [
                    'email'     => $recipient->getEmail(),
                    'header_to' => $toIdentityString,
                ],
                'tags' => $tags,
            ];
        }

        if (count($normalizedCc)) {
            $parameters['content']['headers']['CC'] = IdentityUtils::buildIdentityString($normalizedCc);
        }

        return json_encode($parameters);
    }
protected function format ( MessageInterface $ message ) { $ from = $ this -> normalizeIdentity ( $ message -> getFrom ( ) ) ; $ parameters = [ 'options' => [ 'transactional' => $ this -> transactional , ] , 'content' => [ 'from' => [ 'name' => $ from -> getName ( ) , 'email' => $ from -> getEmail ( ) , ] , 'subject' => $ message -> getSubject ( ) , 'text' => $ message -> getText ( ) , 'html' => $ message -> getHtml ( ) , ] , ] ; if ( $ message -> getReplyTo ( ) ) { $ parameters [ 'content' ] [ 'reply_to' ] = $ message -> getReplyTo ( ) ; } if ( count ( $ message -> getHeaders ( ) ) ) { $ parameters [ 'content' ] [ 'headers' ] = $ message -> getHeaders ( ) ; } if ( $ message instanceof AttachmentsAwareInterface ) { foreach ( $ message -> getAttachments ( ) as $ attachment ) { $ inline = $ attachment -> getId ( ) !== null ; $ parameters [ 'content' ] [ $ inline ? 'inline_images' : 'attachments' ] [ ] = [ 'type' => $ attachment -> getType ( ) , 'name' => $ inline ? $ attachment -> getId ( ) : $ attachment -> getName ( ) , 'data' => base64_encode ( $ this -> getAttachmentContent ( $ attachment ) ) , ] ; } } if ( $ message instanceof MetadataAwareInterface ) { $ metadata = array_filter ( $ message -> getMetadata ( ) ) ; if ( count ( $ metadata ) ) { $ parameters [ 'metadata' ] = $ metadata ; } } $ tags = [ ] ; if ( $ message instanceof TaggableInterface ) { $ tags = ( array ) $ message -> getTag ( ) ; } $ normalizedTo = $ this -> normalizeIdentities ( $ message -> getTo ( ) ) ; $ normalizedCc = $ this -> normalizeIdentities ( $ message -> getCc ( ) ) ; $ normalizedBcc = $ this -> normalizeIdentities ( $ message -> getBcc ( ) ) ; $ toIdentityString = IdentityUtils :: buildIdentityString ( $ normalizedTo ) ; /** @var \Stampie\Identity[] $merged */ $ merged = array_merge ( $ normalizedTo , $ normalizedCc , $ normalizedBcc ) ; foreach ( $ merged as $ recipient ) { /*
             * The reason we are specifying header_to is so that each recipient can see *everybody* who received
             * the email. Without it, each recipient will only see their email in the To field.
             *
             * IMPORTANT: Do not specify address.name!
             * If given, SparkPost will try to wrap the entire header_to value, mangling it in the process.
             */ $ parameters [ 'recipients' ] [ ] = [ 'address' => [ 'email' => $ recipient -> getEmail ( ) , 'header_to' => $ toIdentityString , ] , 'tags' => $ tags , ] ; } if ( count ( $ normalizedCc ) ) { $ parameters [ 'content' ] [ 'headers' ] [ 'CC' ] = IdentityUtils :: buildIdentityString ( $ normalizedCc ) ; } return json_encode ( $ parameters ) ; }
{@inheritdoc}
{