Mailer.php
[Pman.Core] / Mailer.php
index 199499c..8d0be13 100644 (file)
@@ -77,7 +77,7 @@ class Pman_Core_Mailer {
     var $html_locale = false; // eg. 'en' or 'zh_HK'
     var $images         = array(); // generated list of cid images for sending
     var $attachments = false;
-    var $css_inline = false; // not supported
+    var $css_inline = false; // put the css into the html
     var $css_embed = false; // put the css tags into the body.
     
     var $mail_method = 'SMTP';
@@ -175,10 +175,15 @@ class Pman_Core_Mailer {
             if ($this->replaceImages) {
                 $htmlbody = $this->htmlbodytoCID($htmlbody);    
             }
+            
             if ($this->css_embed) {
-                $htmlbody = $this->htmlbodyCssEmbed($htmlbody);    
-              
+                $htmlbody = $this->htmlbodyCssEmbed($htmlbody);
+            }
+            
+            if ($this->css_inline && strlen($this->css_inline)) {
+                $htmlbody = $this->htmlbodyInlineCss($htmlbody);
             }
+            
         }
         $tmp_opts['nonHTML'] = true;
         
@@ -308,6 +313,7 @@ class Pman_Core_Mailer {
     }
     function send($email = false)
     {
+                       
         $ff = HTML_FlexyFramework::get();
         
         $pg = $ff->page;
@@ -374,7 +380,7 @@ class Pman_Core_Mailer {
     {
         $dom = new DOMDocument();
         // this may raise parse errors as some html may be a component..
-        @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
+        @$dom->loadHTML($html);
         $imgs= $dom->getElementsByTagName('img');
         
         foreach ($imgs as $i=>$img) {
@@ -405,7 +411,7 @@ class Pman_Core_Mailer {
         $dom = new DOMDocument();
         
         // this may raise parse errors as some html may be a component..
-        @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
+        @$dom->loadHTML($html);
         $links = $dom->getElementsByTagName('link');
         $lc = array();
         foreach ($links as $link) {  // duplicate as links is dynamic and we change it..!
@@ -447,7 +453,31 @@ class Pman_Core_Mailer {
         
     }
     
-    
+    function htmlbodyInlineCss($html)
+    {
+        print_R($html);exit;
+        
+        $dom = new DOMDocument();
+        
+        @$dom->loadHTML($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, $body->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)
     {
@@ -515,7 +545,9 @@ class Pman_Core_Mailer {
         }
         
         require_once 'HTTP/Request.php';
-        $a = new HTTP_Request($this->mapurl($url));
+        
+        $real_url = str_replace(' ', '%20', $this->mapurl($url));
+        $a = new HTTP_Request($real_url);
         $a->sendRequest();
         $data = $a->getResponseBody();