<?
class Mailer {

    var $_subject = "";
    var $_body = "";


    function constructor() {}

    function compose($template) {
        $fname_subj = $template.".subj"._TPL_EXTENSION;
        $fname_body = $template._TPL_EXTENSION;
        if(file_exists($fname_subj) && file_exists($fname_body)) {
            $this->_subject = $this->_processMask(file_get_contents($fname_subj));
            $this->_body = $this->_processMask(file_get_contents($fname_body));
            return true;
        } else {
            return false;
        }
    }


    function send($email) {
        mail($email, $this->_subject, $this->_body, "From: ".$_SERVER["SERVER_NAME"]."\r\nContent-type: text/html; charset=us-ascii");
    }



    function _processMask($str) {
        preg_match_all("/\{(\w*)\}/", $str, $m, PREG_PATTERN_ORDER);
        foreach($m[1] as $n => $var) {
            $str = str_replace($m[0][$n], $this->$var, $str);
        }
        return $str;
    }
}
?>