src/mail/Template.php
public function compose(MessageInterface $message, $params = [])
    {
        $this->message = $message;

        if (is_array($this->viewName)) {
            if (isset($this->viewName['html'])) {
                $html = $this->render($this->viewName['html'], $params, $this->htmlLayout);
            }
            if (isset($this->viewName['text'])) {
                $text = $this->render($this->viewName['text'], $params, $this->textLayout);
            }
        } else {
            $html = $this->render($this->viewName, $params, $this->htmlLayout);
        }

        if (isset($html)) {
            $this->message->setHtmlBody($html);
        }
        if (isset($text)) {
            $this->message->setTextBody($text);
        } elseif (isset($html)) {
            if (preg_match('~<body[^>]*>(.*?)</body>~is', $html, $match)) {
                $html = $match[1];
            }
            // remove style and script
            $html = preg_replace('~<((style|script))[^>]*>(.*?)</\1>~is', '', $html);
            // strip all HTML tags and decode HTML entities
            $text = html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5);
            // improve whitespace
            $text = preg_replace("~^[ \t]+~m", '', trim($text));
            $text = preg_replace('~\R\R+~mu', "\n\n", $text);
            $this->message->setTextBody($text);
        }
    }
public function compose(MessageInterface $message, $params = [])
    {
        $this->message = $message;

        if (is_array($this->viewName)) {
            if (isset($this->viewName['html'])) {
                $html = $this->render($this->viewName['html'], $params, $this->htmlLayout);
            }
            if (isset($this->viewName['text'])) {
                $text = $this->render($this->viewName['text'], $params, $this->textLayout);
            }
        } else {
            $html = $this->render($this->viewName, $params, $this->htmlLayout);
        }

        if (isset($html)) {
            $this->message->setHtmlBody($html);
        }
        if (isset($text)) {
            $this->message->setTextBody($text);
        } elseif (isset($html)) {
            if (preg_match('~<body[^>]*>(.*?)</body>~is', $html, $match)) {
                $html = $match[1];
            }
            // remove style and script
            $html = preg_replace('~<((style|script))[^>]*>(.*?)</\1>~is', '', $html);
            // strip all HTML tags and decode HTML entities
            $text = html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5);
            // improve whitespace
            $text = preg_replace("~^[ \t]+~m", '', trim($text));
            $text = preg_replace('~\R\R+~mu', "\n\n", $text);
            $this->message->setTextBody($text);
        }
    }
public function compose ( MessageInterface $ message , $ params = [ ] ) { $ this -> message = $ message ; if ( is_array ( $ this -> viewName ) ) { if ( isset ( $ this -> viewName [ 'html' ] ) ) { $ html = $ this -> render ( $ this -> viewName [ 'html' ] , $ params , $ this -> htmlLayout ) ; } if ( isset ( $ this -> viewName [ 'text' ] ) ) { $ text = $ this -> render ( $ this -> viewName [ 'text' ] , $ params , $ this -> textLayout ) ; } } else { $ html = $ this -> render ( $ this -> viewName , $ params , $ this -> htmlLayout ) ; } if ( isset ( $ html ) ) { $ this -> message -> setHtmlBody ( $ html ) ; } if ( isset ( $ text ) ) { $ this -> message -> setTextBody ( $ text ) ; } elseif ( isset ( $ html ) ) { if ( preg_match ( '~<body[^>]*>(.*?)</body>~is' , $ html , $ match ) ) { $ html = $ match [ 1 ] ; } // remove style and script $ html = preg_replace ( '~<((style|script))[^>]*>(.*?)</\1>~is' , '' , $ html ) ; // strip all HTML tags and decode HTML entities $ text = html_entity_decode ( strip_tags ( $ html ) , ENT_QUOTES | ENT_HTML5 ) ; // improve whitespace $ text = preg_replace ( "~^[ \t]+~m" , '' , trim ( $ text ) ) ; $ text = preg_replace ( '~\R\R+~mu' , "\n\n" , $ text ) ; $ this -> message -> setTextBody ( $ text ) ; } }
Composes the given mail message according to this template.
@param MessageInterface $message the message to be composed.
@param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
Composes the given mail message according to this template .