string(19) "ViewArticleOrg.html"
/*
* sends a rendered template to a person
*
* @arg string $templateFile name of template file, eg. 'notice.txt'
* @arg array|object $args overlayed data for template.
*/
function sendEmailTemplate($templateFile,$args=array())
{
$content = clone($this);
foreach((array)$args as $k=>$v) {
$content->$k = $v;
}
/* use the regex compiler, as it doesnt parse <tags */
require_once 'HTML/Template/Flexy.php';
$template = new HTML_Template_Flexy( array(
'compiler' => 'Regex',
'filters' => array('SimpleTags','Mail'),
// 'debug'=>1,
));
/* 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;
//echo "PROBLEM: {$parts->message}";
//exit;
}
list($recipents,$headers,$body) = $parts;
$mailOptions = PEAR::getStaticProperty('Mail','options');
$mail = Mail::factory("SMTP",$mailOptions);
$headers
[
'Date'
] = date(
'r'
);
return PEAR::isError($mail) ? $mail : $mail->send($recipents,$headers,$body);
}
A sample template
From: "Demo User" <demo@example.com>
Sender:"Demo User" <demo@example.com>
To: { t.Email }
Subject: { t.someobject.Name } has submitted something for you approval
Content-Type: text/plain; charset=us-ascii
Please Go to this URL to review and approve the details
{ t.baseURL }/review.html