DataObjects/Core_curr_rate.php
[Pman.Core] / Mailer.php
index 6bc55f1..8002ef1 100644 (file)
@@ -16,7 +16,7 @@
  *
  *  $x= new Pman_Core_Mailer($opts)
  *
- *  $opts[
+ *  $x= Pman_Core_Mailer(array(
        page => 
        contents
        template
@@ -31,8 +31,9 @@
           mimetype : 
         ), 
         ......
+        mail_method : (SMTP or SMTPMX)
   
-    ]
+    )
  *
  *  recipents is gathered from the resulting template
  *   -- eg.
@@ -42,7 +43,7 @@
  *  if the file     '
  * 
  * 
- *  $x->asData(); // returns data needed for notify?? - notify should really
+ *  $x->toData(); // returns data needed for notify?? - notify should really
  *                  // just use this to pass around later..
  *
  *  $x->send();
@@ -59,10 +60,13 @@ class Pman_Core_Mailer {
     var $templateDir = false;
     var $locale = false; // eg. 'en' or 'zh_HK'
     
+    
     var $html_locale = false; // eg. 'en' or 'zh_HK'
     var $images         = array(); // generated list of cid images for sending
     var $attachments = false;
     
+    var $mail_method = 'SMTP';
+    
     function Pman_Core_Mailer($args) {
         foreach($args as $k=>$v) {
             // a bit trusting..
@@ -138,9 +142,13 @@ class Pman_Core_Mailer {
             $htmltemplate->compile('mail/'. $templateFile.'.body.html');
             $htmlbody =  $htmltemplate->bufferedOutputObject($content);
             
+            $this->htmlbody = $htmlbody;
+            
             // for the html body, we may want to convert the attachments to images.
 //            var_dump($htmlbody);exit;
-            $htmlbody = $this->htmlbodytoCID($htmlbody);
+            if ($this->replaceImages) {
+                $htmlbody = $this->htmlbodytoCID($htmlbody);    
+            }
             
               
         }
@@ -254,7 +262,8 @@ class Pman_Core_Mailer {
         return array(
             'recipents' => $parts[0],
             'headers' => $parts[1],
-            'body' => $parts[2]
+            'body' => $parts[2],
+            'mailer' => $this
         );
     }
     function send($email = false)
@@ -276,10 +285,20 @@ class Pman_Core_Mailer {
         ///$recipents = array($this->email);
         $mailOptions = PEAR::getStaticProperty('Mail','options');
         //print_R($mailOptions);exit;
-        $mail = Mail::factory("SMTP",$mailOptions);
+        
+        if ($this->mail_method == 'SMTPMX' && empty($mailOptions['mailname'])) {
+            $pg->jerr("Mail[mailname] is not set - this is required for SMTPMX");
+            
+        }
+        
+        $mail = Mail::factory($this->mail_method,$mailOptions);
+        if ($this->debug) {
+            $mail->debug = $this->debug;
+        }
+        
         $email['headers']['Date'] = date('r'); 
         if (PEAR::isError($mail)) {
-             $pg->addEvent("COREMAILER-FAIL",  false, "mail factory failed"); 
+            $pg->addEvent("COREMAILER-FAIL",  false, "mail factory failed"); 
       
             
             return $mail;
@@ -298,8 +317,10 @@ class Pman_Core_Mailer {
                 'To: ' .  ( is_array($rcpts) ? implode(', ', $rcpts) : $rcpts ) .
                 'Subject: '  . @$email['headers']['Subject']
             ); 
-        }  
-       
+        }  else {
+            $pg->addEvent("COREMAILER-FAIL",  false, $ret->toString());
+        }
+        
         return $ret;
     }
     
@@ -377,8 +398,7 @@ class Pman_Core_Mailer {
         
         $cache = ini_get('session.save_path')."/Pman_Core_Mailer-{$user}/" . md5($url);
         if (file_exists($cache) and filemtime($cache) > strtotime('NOW - 1 WEEK')) {
-            $ret =  json_decode($cache);
-            print_r($cache);exit;
+            $ret =  json_decode(file_get_contents($cache), true);
             $ret['file'] = $cache . '.data';
             return $ret;
         }