5 * code that used to be in Pman (sendTemplate / emailTemplate)
10 * $x= new Pman_Core_Mailer($opts)
16 replaceImages => true|false
19 * $x->asData(); // returns data needed for notify?? - notify should really
20 * // just use this to pass around later..
26 class Pman_Core_Mailer {
29 var $contents = false;
30 var $template = false;
31 var $replaceImages = false;
33 function Pman_Core_Mailer($args) {
34 foreach($args as $k=>$v) {
41 * ---------------- Global Tools ---------------
47 $templateFile = $this->template;
48 $args = $this->contents;
50 $content = clone($page);
52 foreach((array)$args as $k=>$v) {
56 $content->msgid = empty($content->msgid ) ? md5(time() . rand()) : $content->msgid ;
58 $ff = HTML_FlexyFramework::get();
59 $http_host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : 'pman.HTTP_HOST.not.set';
60 if (isset($ff->Pman['HTTP_HOST'])) {
61 $http_host = $ff->Pman['HTTP_HOST'];
65 $content->HTTP_HOST = $http_host;
69 // this should be done by having multiple template sources...!!!
71 require_once 'HTML/Template/Flexy.php';
75 if (is_string($template->resolvePath('mail/'.$template.'.body.html')) ) {
76 // then we have a multi-part email...
79 $htmltemplate = new HTML_Template_Flexy( );
80 $htmltemplate->compile('mail/'. $templateFile.'.body.html');
81 $htmlbody = $template->bufferedOutputObject($content);
83 // for the html body, we may want to convert the attachments to images.
88 $template = new HTML_Template_Flexy( array(
92 $template->compile('mail/'. $templateFile.'.txt');
94 /* use variables from this object to ouput data. */
95 $mailtext = $template->bufferedOutputObject($content);
106 //echo "<PRE>";print_R($mailtext);
108 /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
109 require_once 'Mail/mimeDecode.php';
110 require_once 'Mail.php';
112 $decoder = new Mail_mimeDecode($mailtext);
113 $parts = $decoder->getSendArray();
114 if (PEAR::isError($parts)) {
116 //echo "PROBLEM: {$parts->message}";
123 $parts[1]['Message-Id'] = '<' . $content->msgid .
124 '@' . $content->HTTP_HOST .'>';
127 // list($recipents,$headers,$body) = $parts;
129 'recipents' => $parts[0],
130 'headers' => $parts[1],
137 $email = $this->toData();
138 if (is_a($email, 'PEAR_Error')) {
141 ///$recipents = array($this->email);
142 $mailOptions = PEAR::getStaticProperty('Mail','options');
143 $mail = Mail::factory("SMTP",$mailOptions);
144 $headers['Date'] = date('r');
145 if (PEAR::isError($mail)) {
148 $oe = error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
149 $ret = $mail->send($email['recipents'],$email['headers'],$email['body']);
150 error_reporting($oe);