<?php

//-----------------------------------------------------------------------------------------
// This class will send an email out easily
// DEPENDECIES: None
//+
//+ LAST UPDATED : 28 June 2009
//----------------------------------------------------------------------------------------

class Postage {


var $email_body;
var $email_to;
var $email_from;
var $email_subject;
var $email_format = 'html';

function Postage($message){
$this->email_body = $message;
}



//_______Email Format______
function EmailFormat($email_format){
if ($email_format == 'html'){
$this->email_format = 'html';
}else{
$this->email_format = 'text';
}
}

//____Additonal vars: To and From__________
function ToFromSubject($email_to, $email_from, $email_subject){
$this->email_to = $email_to;
$this->email_from = $email_from;
$this->email_subject = $email_subject;
}


//____Parse message body__________
function EmailVars($email_vars){
if(is_array($email_vars)){
//replace all vars in message	
foreach($email_vars as $key => $value){
$key = '[var.'.$key.']';
$parsed_message = str_replace($key, $value, $this->email_body);
$this->email_body = $parsed_message;
}
}
}


//____SEND email now_______________________
function SendNow(){
if ( $this->email_format == 'html' ){
	$from = $this->email_from;
	$headers = "From: $from\n";
	$headers .= "Reply-To: $from\n";
	$headers .= "Return-Path: $from\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";

    mail($this->email_to, $this->email_subject, $this->email_body,$headers);
} else {
	mail($this->email_to, $this->email_subject, $this->email_body, "From: $from");
}
}




//==================================================  Usage   ============================================================
/*

    //_______Send Email
    $message = 'Hello how are you'; //or use html code with [var.dads] as dynamic vars
    $subject = 'Come join me';
    $notify = new Postage($message);
    $notify->EmailFormat('html');
    $notify->ToFromSubject($email_address, 'admin@floopo.com', $subject);
    $notify->EmailVars(array('user_name'=>$user_name, 'activation_code'=>$activation_code)); //additional vars to use in email html
    $notify->SendNow();


    //_____example message__________
    // note the [var.xxx] has nothing to do with TBS, is just any var

    ----------------------------------------------------------------------------------------------------
    'Hello [var.user_name]

     Thank you for joining floopo.com
     To complete your registration click the link below (or copy and paste into your browser)
     http://www.floopo.com/index.php?option=com_index&type=1&activation_code=[var.activation_code]
     
     Floopo Team

     Start talking!!'
    ------------------------------------------------------------------------------------------------------


*/



}//End Notify Class



?>