DataObjects/Core_notify.php
[Pman.Core] / Mailer.php
index 32c934c..d71b171 100644 (file)
  */
 
 class Pman_Core_Mailer {
-    
+    var $debug          = false;
     var $page           = false; /* usually a html_flexyframework_page */
     var $contents       = false; /* object or array */
     var $template       = false; /* string */
     var $replaceImages  = false; /* boolean */
     var $rcpts   = false;
+    var $templateDir = false;
     
     var $images         = array(); // generated list of cid images for sending
     
@@ -90,8 +91,14 @@ class Pman_Core_Mailer {
         
         require_once 'HTML/Template/Flexy.php';
         
+        $tmp_opts = array();
+        if (!empty($this->templateDir)) {
+            $tmp_opts['templateDir'] = $this->templateDir;
+        }
+        
+        
         $htmlbody = false;
-        $htmltemplate = new HTML_Template_Flexy(  );
+        $htmltemplate = new HTML_Template_Flexy( $tmp_opts );
 
         if (is_string($htmltemplate->resolvePath('mail/'.$templateFile.'.body.html')) ) {
             // then we have a multi-part email...
@@ -104,27 +111,18 @@ class Pman_Core_Mailer {
             
             $htmlbody = $this->htmlbodytoCID($htmlbody);
             
-             
+              
         }
-        
-        
-        
-        $template = new HTML_Template_Flexy( array(
-                'nonHTML' => true,
-        ));
+        $tmp_opts['nonHTML'] = true;
+        // $tmp_opts['force'] = true;
+        $template = new HTML_Template_Flexy(  $tmp_opts );
         
         $template->compile('mail/'. $templateFile.'.txt');
         
         /* use variables from this object to ouput data. */
         $mailtext = $template->bufferedOutputObject($content);
-        
-        
-        
-        
-        
-        
-        
-        
+        //print_r($mailtext);exit;
+       
         
         
         //echo "<PRE>";print_R($mailtext);
@@ -172,8 +170,6 @@ class Pman_Core_Mailer {
         
         }
         
-        
-        
        // list($recipents,$headers,$body) = $parts;
         return array(
             'recipents' => $parts[0],
@@ -188,14 +184,23 @@ class Pman_Core_Mailer {
         if (is_a($email, 'PEAR_Error')) {
             return $email;
         }
+        if ($this->debug) {
+            echo '<PRE>';echo htmlspecialchars(print_r($email,true));
+        }
         ///$recipents = array($this->email);
         $mailOptions = PEAR::getStaticProperty('Mail','options');
+        //print_R($mailOptions);exit;
         $mail = Mail::factory("SMTP",$mailOptions);
         $headers['Date'] = date('r'); 
         if (PEAR::isError($mail)) {
             return $mail;
         } 
         $rcpts = $this->rcpts == false ? $email['recipents'] : $this->rcpts;
+        
+        if (!empty($this->contents['bcc']) && is_array($this->contents['bcc'])) {
+            $rcpts =array_merge(is_array($rcpts) ? $rcpts : array($rcpts), $this->contents['bcc']);
+        }
+        
         $oe = error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
         $ret = $mail->send($rcpts,$email['headers'],$email['body']);
         error_reporting($oe);