How to setup email system

Discussion in 'Directories' started by humm, Jun 16, 2006.

  1. #1
    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. :)
     
    humm, Jun 16, 2006 IP
  2. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    Chemo, Jun 16, 2006 IP
  3. humm

    humm बहादुर बच्चा

    Messages:
    4,346
    Likes Received:
    850
    Best Answers:
    0
    Trophy Points:
    310
    #3
    Thanks a lot buddy. What are those email template system in phpld then? :confused:

    Can't I setup a email system using it. ?
     
    humm, Jun 16, 2006 IP
  4. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Don't know...I've never used phpld. I thought you custom rolled your own application.

    Bobby
     
    Chemo, Jun 16, 2006 IP
  5. humm

    humm बहादुर बच्चा

    Messages:
    4,346
    Likes Received:
    850
    Best Answers:
    0
    Trophy Points:
    310
    #5
    Anyone else who can help me? :(
     
    humm, Jun 17, 2006 IP
  6. deluxdon

    deluxdon Catch Me If You Can...!!!™ Staff

    Messages:
    25,481
    Likes Received:
    1,943
    Best Answers:
    32
    Trophy Points:
    480
    #6
    Sent u PM. Check it and reply back to us. We try to help u to getting out of this problem.

    :)
     
    deluxdon, Jun 17, 2006 IP