_tpl = $tpl; $this->caching=false; $this->compile_check=true; $this->template_dir = $globals->spoolroot . "/templates/"; $this->compile_dir = $globals->spoolroot . "/spool/templates_c/"; $this->config_dir = $globals->spoolroot . "/configs/"; $this->register_outputfilter('mail_format'); $this->register_function('from', 'set_from'); $this->register_function('to', 'set_to'); $this->register_function('cc', 'set_cc'); $this->register_function('bcc', 'set_bcc'); $this->register_function('subject', 'set_subject'); } // }}} // {{{ function send() function send() { // do not try to optimize, in the templates, some function can modify our object, then we // have to fetch in the first time, and only then send the mail. $body = $this->fetch($this->_tpl); $mailer = new HermesMailer(); $mailer->setFrom($this->_from); $mailer->addTo(implode(',',$this->_to)); $mailer->setSubject($this->_subject); if (!empty($this->_cc)) { $mailer->addCc(implode(',',$this->_cc)); } if (!empty($this->_bcc)) { $mailer->addBcc(implode(',',$this->_bcc)); } $mailer->setTxtBody($body); $mailer->send(); } // }}} } // }}} // {{{ function mail_format() /** used to remove the empty lines due to {from ...}, {to ...} ... functions */ function mail_format($output, &$smarty) { return wordwrap("\n".trim($output)."\n",75); } // }}} // {{{ function format_addr() function format_addr(&$params) { if (isset($params['full'])) { return $params['full']; } elseif (empty($params['text'])) { return $params['addr']; } else { return $params['text'].' <'.$params['addr'].'>'; } } // }}} // {{{ function set_from() /** template function : from. * {from full=...} for an already formatted address * {from addr=... [text=...]} else */ function set_from($params, &$smarty) { $smarty->_from = format_addr($params); } // }}} // {{{ function set_to() /** template function : to. * {to full=...} for an already formatted address * {to addr=... [text=...]} else */ function set_to($params, &$smarty) { $smarty->_to[] = format_addr($params); } // }}} // {{{ function set_cc() /** template function : cc. * {cc full=...} for an already formatted address * {cc addr=... [text=...]} else */ function set_cc($params, &$smarty) { $smarty->_cc[] = format_addr($params); } // }}} // {{{ function set_bcc() /** template function : bcc. * {bcc full=...} for an already formatted address * {bcc addr=... [text=...]} else */ function set_bcc($params, &$smarty) { $smarty->_bcc[] = format_addr($params); } // }}} // {{{ function set_subject() /** template function : subject. * {subject text=...} */ function set_subject($params, &$smarty) { $smarty->_subject = $params['text']; } // }}} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?>