Re: Re[2]: [PHP] variables in a e-mail

From: Date: Tue, 19 Jun 2001 17:15:35 +0000
Subject: Re: Re[2]: [PHP] variables in a e-mail
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-54399@lists.php.net to get a copy of this message
"Richard Kurth" <rkurth@pacifier.com> wrote: > This is pretty much what I want to do. I want to have a e-mail script > in my application and have it so the user can customize the e-mail that > is sent out in a configure file. Say he wants to send a recurring bill > to his customers and he wants it to look a certain way. He would design > the e-mail using placeholders and the it would be processed and the data > would be filled in. Do you know of any examples of this in any program > that is out there. You need to use or build a template engine. Search google.com for "php template engine". Smarty and FastTemplates come to mind. Or build you own. All you really need to do is read a template file (using functions like fopen, fread, while) and replace template variables with their values. The easiest way is to make template variables like %%my_var%%, then read each line of the template file one at a time and use str_replace() to replace anything matching %%my_var%% with $my_var, looping through all possible valid template variables (maybe stored in an array) as each line is parsed. Or if you prefer you can use regular expressions to replace all template variables with their corresponding PHP variable. As you loop through each line and parse it add the parsed line to a string. When you're done include the string in a mail() function to email it or use a file function to write it to a file. -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/

« previous php.general (#54399) next »