How do I setup email system in my directory for link submitted, link approved, link rejected? I tried some template, but nothin seemed to work properly. Plz help me on this.
You can either use str_replace() or eval() depending on your preference. The general steps are easy enough: (1) Load template file (2) Replace placeholders with variable data (3) Email resulting string to visitor As an example, let's say I have this template file located at /templates/approved.tpl: Your submission has been APPROVED Resource ID : {$link_id} Title : {$title} Url : {$url} Description : {$description} Category : {$category} Contact name: {$contact_name} Email : {$email} Password : {$password} ====================== REVIEWING EDITOR NOTES ====================== {$editors_note} Regards, Directory Team Code (markup): Next, I need to create a fast (and secure) template class like this: <?php class Template{ var $template; var $variables; function Template($template){ $this->template = @file_get_contents($template); $this->resetVars(); } # end class constructor function resetVars(){ $this->variables = array(); } #end function resetVars() function Add($var_name, $var_data){ $this->variables[$var_name] = $var_data; } # end fucntion Add() function AddArray($array){ if ( !is_array($array) ){ return; } foreach ( $array as $name => $data ){ $this->Add($name, $data); } return; } # end function AddArray() function Evaluate($direct_output = false){ $template = addslashes($this->template); foreach ( $this->variables as $variable => $data ){ $$variable = $data; } # end foreach eval("\$template = \"$template\";"); if ( $direct_output ) { echo stripslashes($template); } else { return stripslashes($template); } } # end function Evaluate() } # end class ?> PHP: OK...so now you have your template file and the template class. Now it's time to get some business logic done and get the variable data. An example of the procedural code might look like this: // Define and execute the SQL // This part left out intentionally...don't know you're DB scheme /* * Include the template class */ include_once('./template.class.php'); /* * Define the template to be used * Note: probably want to use a simple switch for approve, reject, etc */ $template_file = 'templates/approved.tpl'; /* * Instantiate the object */ $template =& new Template($template_file); /* * Loop the results */ foreach ( $result as $data ){ $template->resetVars(); $template->AddArray($data); $output = $template->Evaluate(); // Be sure to use the proper parameters! mail( fill in the parameters per your tastes ); } PHP: I did not provide the SQL statement, mysql function use, or demonstrate the mail function. I hope these are fairly obvious. My main goal was to illustrate a quick template class so that you can format your emails. As another note you might consider using an email class that allows mixed type messages (both text and HTML versions). Good luck! Bobby
Thanks a lot buddy. What are those email template system in phpld then? Can't I setup a email system using it. ?