Mailer.php
[Pman.Core] / Mailer.php
index a1ab4f8..e1985bf 100644 (file)
@@ -180,8 +180,8 @@ class Pman_Core_Mailer {
                 $htmlbody = $this->htmlbodyCssEmbed($htmlbody);
             }
             
-            if ($this->css_inline) {
-                $htmlbody = $this->htmlbodyinlineCss($htmlbody);
+            if ($this->css_inline && strlen($this->css_inline)) {
+                $htmlbody = $this->htmlbodyInlineCss($htmlbody);
             }
             
         }
@@ -453,7 +453,29 @@ class Pman_Core_Mailer {
         
     }
     
-    
+    function htmlbodyInlineCss($html)
+    {
+        $dom = new DOMDocument();
+        
+        @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
+        
+        $html = $dom->getElementsByTagName('html');
+        $head = $dom->getElementsByTagName('head');
+        $body = $dom->getElementsByTagName('head');
+        
+        if(!$head->length){
+            $head = $dom->createElement('head');
+            $html->item(0)->insertBefore($head, $html->item(0));
+            $head = $dom->getElementsByTagName('head');
+        }
+        
+        $s = $dom->createElement('style');
+        $e = $dom->createTextNode($this->css_inline);
+        $s->appendChild($e);
+        $head->item(0)->appendChild($s);
+        
+        return $dom->saveHTML();
+    }
     
     function fetchImage($url)
     {