class DataObjects_Person {
var $id;
var $name;
var $password;
var $cleartextPassword;
var $email;
function sendEmail($templateFile,$content) {
$content = is_object($content) ? $content : (object) $content;
foreach(get_object_vars($this) as $k=>$v) {
$content->$k = $v;
}
/* use the regex compiler, as it doesnt parse <tags */
$template = new HTML_Template_Flexy( array(
'compiler' => 'Regex',
'filters' => array('SimpleTags','Mail'),
));
/* compile a text file (email template) */
$template->compile($templateFile);
/* use variables from this object to ouput data. */
$mailtext = $template->bufferedOutputObject($content);
//echo "<PRE>";print_R($mailtext);
/* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
require_once 'Mail/mimeDecode.php';
require_once 'Mail.php';
$decoder = new Mail_mimeDecode($mailtext);
$parts = $decoder->getSendArray();
if (PEAR::isError($parts)) {
return $parts;
}
list($recipents,$headers,$body) = $parts;
$mailOptions = PEAR::getStaticProperty('Mail','options');
$mail = Mail::factory("SMTP",$mailOptions);
return PEAR::isError($mail) ? $mail : $mail->send($recipents,$headers,$body);
}
} |