DataObjects/Core_person_signup.php
[Pman.Core] / DataObjects / Core_email.php
index 94bd3c3..99ed55d 100644 (file)
@@ -242,7 +242,9 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
             $element->setAttribute('height', '1');
 
             $html = $doc->getElementsByTagName('html');
-            $html->item(0)->appendChild($element);
+            if ($html->length) {
+                $html->item(0)->appendChild($element);
+            }
             
             $this->plaintext = str_replace("{unsubscribe_link}", $unsubscribe, $this->plaintext);
         }
@@ -267,17 +269,23 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
         }
         
         if(empty($this->id)){
-            return PEAR::raiseError("template [{$contents['template']}]has not been set");
+            $p = new PEAR();
+            return $p->raiseError("template [{$contents['template']}]has not been set");
+        }
+        if(empty($contents['subject'])){
+           $contents['subject'] = $this->subject; 
         }
         
-        $contents['subject'] = $this->subject;
+        if(!empty($contents['rcpts']) && is_array($contents['rcpts'])){
+            $contents['rcpts'] = implode(',', $contents['rcpts']);
+        }
         
         $ui = posix_getpwuid(posix_geteuid());
         
         $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.txt';
         
-        if(!$this->isGenerated($cachePath)){
-            $this->cachedMailWithOutImages($force, false);
+        if($force || !$this->isGenerated($cachePath)){
+            $this->cachedMailWithOutImages($force, empty($contents['replace_links']) ? false : $contents['replace_links']);
         }
          
         require_once 'Pman/Core/Mailer.php';
@@ -287,7 +295,6 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
         $r = new Pman_Core_Mailer(array(
             'template'=> $this->tableName() . '-' . $this->id,
             'templateDir' => $templateDir,
-            'rcpts' => 'edward@roojs.com',
             'page' => $this,
             'contents' => $contents
         ));
@@ -305,13 +312,12 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
             return $ret;
         }
         
-        return $r->send($ret);
+        return $r->send();
     }
     
     function cachedMailWithOutImages($force = false, $replace_links = true)
     {  
         
-        
         $ui = posix_getpwuid(posix_geteuid());
         
         $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.txt';
@@ -331,10 +337,11 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
         $fh = fopen($cachePath, 'w');
 
         fwrite($fh, implode("\n", array(
-            "From: {t.messageFrom():h} ",
-            "To: {t.person.getEmailFrom():h} ",
+            "From: {if:t.messageFrom}{t.messageFrom:h}{else:}{t.messageFrom():h}{end:}",
+            "To: {if:t.person}{t.person.getEmailFrom():h}{else:}{rcpts:h}{end:}",
             "Subject: {t.subject} ",
-            "X-Message-ID: {t.id} "
+            "X-Message-ID: {t.id} ",
+            "{if:t.replyTo}Reply-To: {t.replyTo:h}{end:}"
         ))."\n");