Ejemplo n.º 1
0
 /**
  * Sets message HTML content.
  * @param string $input message HTML content.
  * @return static self reference.
  *
  * Note: PHPMailer autocreates both html-body and alt-body (and normalizes text for alt-body), so we need not to set
  * additionally text body to create 'multipart/alternative' content-type.
  *
  * We also try to make possible to call [[setHtmlBody()]] from elsewhere, not only from [[compose()]],
  * for simple cases, when we have no params to pass to the view to build html, just text.
  * Othervise you do everything via Mailer [[compose()]] function, passing params their.
  */
 public function setHtmlBody($input)
 {
     if (array_key_exists('ishtml', $this->mailer->config) && $this->mailer->config['ishtml'] === false) {
         //prevent sending html messages if it is explicitly denied in application config
         $this->setTextBody($input);
     } else {
         if (preg_match('|<body[^>]*>(.*?)</body>|is', $input) != 1) {
             //html was not already rendered by view - lets do it
             if (empty($this->mailer->htmlView)) {
                 $html = $this->mailer->render($this->mailer->htmlLayout, ['content' => $input], false);
             } else {
                 //The most simple case is supposed here - your html view file should use '$text' variable
                 $html = $this->mailer->render($this->mailer->htmlView, ['text' => $input], $this->mailer->htmlLayout);
             }
         } else {
             $html = $input;
         }
         //TODO: check usage and default behavior of '$basedir' argument (used for images)
         $this->mailer->adapter->msgHTML($html, $basedir = '', true);
     }
     return $this;
 }