protected function setBody($body, $contentType)
    {
        $message = $this->getSwiftMessage();
        $oldBody = $message->getBody();
        $charset = $message->getCharset();
        if (empty($oldBody)) {
            $parts = $message->getChildren();
            $partFound = false;
            foreach ($parts as $key => $part) {
                if (!($part instanceof \Swift_Mime_Attachment)) {
                    /* @var $part \Swift_Mime_MimePart */
                    if ($part->getContentType() == $contentType) {
                        $charset = $part->getCharset();
                        unset($parts[$key]);
                        $partFound = true;
                        break;
                    }
                }
            }
            if ($partFound) {
                reset($parts);
                $message->setChildren($parts);
                $message->addPart($body, $contentType, $charset);
            } else {
                $message->setBody($body, $contentType);
            }
        } else {
            $oldContentType = $message->getContentType();
            if ($oldContentType == $contentType) {
                $message->setBody($body, $contentType);
            } else {
                $message->setBody(null);
                $message->setContentType(null);
                $message->addPart($oldBody, $oldContentType, $charset);
                $message->addPart($body, $contentType, $charset);
            }
        }
    }
protected function setBody($body, $contentType)
    {
        $message = $this->getSwiftMessage();
        $oldBody = $message->getBody();
        $charset = $message->getCharset();
        if (empty($oldBody)) {
            $parts = $message->getChildren();
            $partFound = false;
            foreach ($parts as $key => $part) {
                if (!($part instanceof \Swift_Mime_Attachment)) {
                    /* @var $part \Swift_Mime_MimePart */
                    if ($part->getContentType() == $contentType) {
                        $charset = $part->getCharset();
                        unset($parts[$key]);
                        $partFound = true;
                        break;
                    }
                }
            }
            if ($partFound) {
                reset($parts);
                $message->setChildren($parts);
                $message->addPart($body, $contentType, $charset);
            } else {
                $message->setBody($body, $contentType);
            }
        } else {
            $oldContentType = $message->getContentType();
            if ($oldContentType == $contentType) {
                $message->setBody($body, $contentType);
            } else {
                $message->setBody(null);
                $message->setContentType(null);
                $message->addPart($oldBody, $oldContentType, $charset);
                $message->addPart($body, $contentType, $charset);
            }
        }
    }
protected function setBody ( $ body , $ contentType ) { $ message = $ this -> getSwiftMessage ( ) ; $ oldBody = $ message -> getBody ( ) ; $ charset = $ message -> getCharset ( ) ; if ( empty ( $ oldBody ) ) { $ parts = $ message -> getChildren ( ) ; $ partFound = false ; foreach ( $ parts as $ key => $ part ) { if ( ! ( $ part instanceof \ Swift_Mime_Attachment ) ) { /* @var $part \Swift_Mime_MimePart */ if ( $ part -> getContentType ( ) == $ contentType ) { $ charset = $ part -> getCharset ( ) ; unset ( $ parts [ $ key ] ) ; $ partFound = true ; break ; } } } if ( $ partFound ) { reset ( $ parts ) ; $ message -> setChildren ( $ parts ) ; $ message -> addPart ( $ body , $ contentType , $ charset ) ; } else { $ message -> setBody ( $ body , $ contentType ) ; } } else { $ oldContentType = $ message -> getContentType ( ) ; if ( $ oldContentType == $ contentType ) { $ message -> setBody ( $ body , $ contentType ) ; } else { $ message -> setBody ( null ) ; $ message -> setContentType ( null ) ; $ message -> addPart ( $ oldBody , $ oldContentType , $ charset ) ; $ message -> addPart ( $ body , $ contentType , $ charset ) ; } } }
Sets the message body.
If body is already set and its content type matches given one, it will
be overridden, if content type miss match the multipart message will be composed.
@param string $body body content.
@param string $contentType body content type.
Sets the message body . If body is already set and its content type matches given one it will be overridden if content type miss match the multipart message will be composed .