Mailer.php
authorAlan Knowles <alan@roojs.com>
Wed, 22 Aug 2012 03:24:45 +0000 (11:24 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 22 Aug 2012 03:24:45 +0000 (11:24 +0800)
Mailer.php

index cf44cce..dce1077 100644 (file)
@@ -36,7 +36,101 @@ class Pman_Core_Mailer {
             $this->$k =  $v;
         }
     }
+     
+    /**
+     * ---------------- Global Tools ---------------   
+     */
     
+    function toData(, $args)
+    {
+    
+        $templateFile = $this->template;
+        $args = $this->contents;
+        
+        $content  = clone($page);
+        
+        foreach((array)$args as $k=>$v) {
+            $content->$k = $v;
+        }
+        
+        $content->msgid = empty($content->msgid ) ? md5(time() . rand()) : $content->msgid ;
+        
+        $ff = HTML_FlexyFramework::get();
+        $http_host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : 'pman.HTTP_HOST.not.set';
+        if (isset($ff->Pman['HTTP_HOST'])) {
+            $http_host  = $ff->Pman['HTTP_HOST'];
+        }
+        
+        
+        $content->HTTP_HOST = $http_host;
+        
+        
+        
+        // this should be done by having multiple template sources...!!!
+        
+        require_once 'HTML/Template/Flexy.php';
+        
+        $htmlbody = false;
+        
+        if (is_string($template->resolvePath('mail/'.$template.'.body.html')) ) {
+            // then we have a multi-part email...
+            
+            
+            $htmltemplate = new HTML_Template_Flexy(  );
+            $htmltemplate->compile('mail/'. $templateFile.'.body.html');
+            $htmlbody =  $template->bufferedOutputObject($content);
+            
+            // for the html body, we may want to convert the attachments to images.
+            
+            
+             
+        } 
+        $template = new HTML_Template_Flexy( array(
+                'nonHTML' => true,
+        ));
+        
+        $template->compile('mail/'. $templateFile.'.txt');
+        
+        /* use variables from this object to ouput data. */
+        $mailtext = $template->bufferedOutputObject($content);
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        //echo "<PRE>";print_R($mailtext);
+        
+        /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
+        require_once 'Mail/mimeDecode.php';
+        require_once 'Mail.php';
+        
+        $decoder = new Mail_mimeDecode($mailtext);
+        $parts = $decoder->getSendArray();
+        if (PEAR::isError($parts)) {
+            return $parts;
+            //echo "PROBLEM: {$parts->message}";
+            //exit;
+        } 
+        
+        
+        
+        
+        $parts[1]['Message-Id'] = '<' .   $content->msgid   .
+                                     '@' . $content->HTTP_HOST .'>';
+        
+        
+       // list($recipents,$headers,$body) = $parts;
+        return array(
+            'recipents' => $parts[0],
+            'headers' => $parts[1],
+            'body' => $parts[2]
+        );
+    }