Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
E-mail Message Text Generation (0 Comments)
Admin: Posted Date: April 4, 2010

E-mail Message Text Generation is a PHP tool to format and manage email messages associated with automated tasks on your website. It provides for simplified linking of scripts sending messages to templates for message formatting.

E-mail Message Text Generation Class


PHP classes library, that allows you to change e-mail message text and template engines easily, makes scripts code readable, with easy to change logic.

Very often it is necessary to send electronic message from PHP-scripts, for example after a new user registered in the system. Usually message sending is built in right into the registration script.

Example:

<?php
// User registration here
// ...
// Now sending a message to User
// Create E-mail message text right here
$letterTxt = “
Dear $userName,
You have successfully registered in our system.
Please use following login and password to enter our system:
Login: $userLogin
Password: $userPassword
With best regards,
Administration”;
// Sending letter
// ...
?>

Aforesaid variant of sending message is totally unreadable, when the letter text is of a big size (which happens very often) and contains formatting and a lot of variables. Saying nothing that to translate the text you will have to change the script which inevitably will cause mistakes. To transfer the letter into HTML becomes absolutely an unsolvable task.

To make a work easier for programmer and separate letter text from source codes template engines are used (they also have advanced possibilities for processing of variables). Then you must create an object of the template engine, indicate the name of the template is, and set variables:

Example:

<?php
// User registration here
// ...
// Now sending a message to User
// 1.Including template engine library
require_once("smarty/Smarty.class.php");
// 2.Creating instance of template object
$tpl = new Smarty;
// 3.Assigning variables to the letter’s text
$tpl->assign('userName',$userName);
$tpl->assign('userLogin',$userLogin);
$tpl->assign('userPassword',$userPassword);
// 4.Generating letter’s text
$letterTxt = $tpl->fetch('letter.tpl');
If (PEAR::isError($letterTxt)) die ($letterTxt->getMessage());
// Sending letter
// ...
?>
                                

In case you need to change a template engine (for example to replace Smarty template engine with Fast Template), set of variables, the name of a file containing text of the letter, you have to change source code of the program (as for aforesaid example you have to change all four points).

The same code but using Fast Template:

<?php
// User registration here
// ...
// Now sending a message to User
// 1.Including template engine library
require_once("class.FastTemplate.php3");
// 2.Creating instance of template object
$tpl = new FastTemplate("/path/to/templates");
// 3.Assigning variables to the letter’s text
$tpl->assign($_REQUEST);
// 4.Generating letter’s text
$tpl->parse(MAIN, "letter");
$letterTxt = $tpl->fetch("MAIN");
// Sending letter
// ...
?>

So you need a programmer for that, for whom it will take a lot of time (as to change libraries is much harder that merely to change the letter text).

Mym library of PHP-classes allows not only to remove the text of a letter from the programming code, but also a template engine and the process of setting variables for the text of the letter as well.

Registration script will look like that:

<?php
// User registration here
// ...
// Now sending a message to User
// 1.Including mym library
require_once("mym/mym_Letter.php");
// 2.Creating instance of letter object
$tpl = mym_Letter::factory($conf[‘tplEngine’],$conf[$conf[‘tplEngine’]][‘tplConf’]);
If (PEAR::isError($tpl)) die ($tpl->getMessage());
// 3.Generating letter’s text
$letterTxt = $tpl->generateText($conf[‘tplName’],$_REQUEST);
If (PEAR::isError($letterTxt)) die ($letterTxt->getMessage());
// Sending message
// ...
?>

Now, in case you will have to replace template engine (Smarty with Fast Template), YOU WON’T NEED TO CHANGE A TEXT OF THE LETTER AT ALL! You just have to change the name of the template engine in the configuration array (hash). This way you can achieve full independence of programming code from text letter generation.

Library features and benefits

  • Totally documented methods and properties of classes make handling of the library easier and more transparent
  • The library was created on the basis of design patterns—recommendations of the programmers’ international community of solving standard project-oriented tasks—which guarantees high quality and flexibility of the programming code.
  • Proper exception/errors handling—each method of the library processes exceptions properly and in critical cases returns the object of the error indicating the exact place of the bug—minimizes the time spent on finding a mistake and will reduce ineffective time losses.
  • Installation instruction: detailed instruction of library installation allows spending much less time for setting up.
  • For easier understanding of working principles installation instruction contains UML-diagrams as illustrations.
  • Detailed examples of usage for fast and simple start.
  • Developer’s instructions: to create your own modules easily there is an instruction how to do it. Update the library according your system requirements spending minimum of time!
                                  


  • Additional consulting on installation: in case you have decided to write your own module for the library and met a mistake you can not understand our experts would be pleased to help you for a tiny reward. You will save a lot of time and nerves giving a task for those who understand it perfectly.
  • Life time guarantee: all mistakes emerging while using library will be corrected for free during all time of usage. There is only one condition: our code must not be modified.
  • Changing of template engine, the template itself and its configuration parameters is carried out by mere changing of one parameter of configuration, which extremely facilitates and speeds up complex procedure of script logic modification.
  • Easy realization of such possibilities like translating into other languages and changing of a letter format. Just analyze the script language and insert letter template from the appropriate directory.
  • You can use the library not only for text letter generation, but for any other needs, for example for displaying web pages. All advantages of removing text from the initial script can be perfectly used for the whole of your site!
Requirements:
  • PHP 4.x, 5.x

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: