DataObjects/core.sql
[Pman.Core] / Mailer.php
index 9107afa..8fc6021 100644 (file)
        replaceImages => true|false,
        locale => 'en' .... or zh_hk....
        rcpts => array()   // override recipients..
+       attachments => array(
+        array(
+          file: 
+          name : (optional) - uses basename of file
+          mimetype : 
+        ), 
+        ......
+  
     ]
  *
  *  recipents is gathered from the resulting template
@@ -52,7 +60,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;
     
     function Pman_Core_Mailer($args) {
         foreach($args as $k=>$v) {
@@ -116,14 +124,15 @@ class Pman_Core_Mailer {
         }
         
         $htmlbody = false;
-        $htmltemplate = new HTML_Template_Flexy( $tmp_opts );
-
+        $html_tmp_opts = $tmp_opts;
+        $htmltemplate = new HTML_Template_Flexy( $html_tmp_opts );
         if (is_string($htmltemplate->resolvePath('mail/'.$templateFile.'.body.html')) ) {
             // then we have a multi-part email...
-            $html_tmp_opts = $tmp_opts;
+            
             if (!empty($this->html_locale)) {
                 $html_tmp_opts['locale'] = $this->html_locale;
             }
+            $htmltemplate = new HTML_Template_Flexy( $html_tmp_opts );
             
             $htmltemplate->compile('mail/'. $templateFile.'.body.html');
             $htmlbody =  $htmltemplate->bufferedOutputObject($content);
@@ -163,6 +172,8 @@ class Pman_Core_Mailer {
             //exit;
         } 
         
+        $isMine = false;
+        
         require_once 'Mail/mime.php';
         $mime = new Mail_mime(array(
             'eol' => "\n",
@@ -197,11 +208,40 @@ class Pman_Core_Mailer {
                     $cdata['contentid']
                 );
             }
-            $parts[2] = $mime->get();
-            $parts[1] = $mime->headers($parts[1]);
+            $isMine = true;
+        }
         
+        if($this->attachments){
+            //if got a attachments
+            
+            $header = $mime->headers($parts[1]);
+            
+            if(preg_match('/text\/html/', $header['Content-Type'])){
+                $mime->setHTMLBody($parts[2]);
+            }else{
+                $mime->setTXTBody($parts[2]);
+            }
+            
+            foreach($this->attachments as $attch){
+                $mime->addAttachment(
+                        $attch['file'],
+                        $attch['mimetype'],
+                        $attch['name'],
+                        false
+                );
+            }
+            
+            $isMine = true;
         }
         
+        if($isMine){
+            $parts[2] = $mime->get();
+            $parts[1] = $mime->headers($parts[1]);
+        }
+//        echo '<PRE>';
+//        print_r('parts');
+//        print_r($parts[2]);
+//        exit;
        // list($recipents,$headers,$body) = $parts;
         return array(
             'recipents' => $parts[0],