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

2001-06-20 Thread Alexander Wagner

Hiho,

Richard Kurth wrote:
> Hello Alexander,
> 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. I do better when I can see complete examples to be
> able to get the full picture

I, personally, know only one, which you won't be able to look at, unless you 
pay the rather high price, and even then, you'd be buggered by german 
source-comments.
Well, I think what you have to do is clear:
Get a template with the placeholders in, this is what the user has to provide.
Find out who shall recieve this mail, and get data about them (name, how much 
they paid or whatever you use those bills for). Then do the replacements once 
and present the user a preview of the mail, so he can be sure hi didn't 
mispell any placeholders.
If he still wants to send the mails, send each reciever a mail, and do the 
replacements every time. That should do it.

regards
Wagner

-- 
"Isn't it strange? The same people who laugh at gypsy fortune tellers take 
economists seriously."
 - Cincinnati Enquirer   



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

2001-06-19 Thread Steve Werby

"Richard Kurth" <[EMAIL PROTECTED]> 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/




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

2001-06-19 Thread Bruin, Bolke de

Use templates

instead of sending it to the webbrowser send it as an email...

http://www.phpbuilder.com for more info



-Oorspronkelijk bericht-
Van: Richard Kurth [mailto:[EMAIL PROTECTED]]
Verzonden: Tuesday, June 19, 2001 4:51 AM
Aan: [EMAIL PROTECTED]; Alexander Wagner
Onderwerp: Re[2]: [PHP] variables in a e-mail


Hello Alexander,
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. I do better when I can see complete examples to be
able to get the full picture

Monday, June 18, 2001, 4:01:45 PM, you wrote:

Alexander Wagner> Hiho,

Alexander Wagner> Richard Kurth wrote:
>> How can I add a variable to an e-mail on the fly. Say I have a form on
>> my page that the user fells in with data. but when he fills in the
>> message things like Hello,$Variable are added before it is sent. Does
>> this make sence

Alexander Wagner> Of course it does.
Alexander Wagner> However, variables are not the way to go. The mails are
not parsed, so 
Alexander Wagner> variables won't do you any good. You'll have to use
Placeholders. Something 
Alexander Wagner> like this:

Alexander Wagner> $mail_template = 
Alexander Wagner> "Hi ##firstname## ##lastname##,
Alexander Wagner> how are you...";

Alexander Wagner> Now you can continue with str_replace():
Alexander Wagner> $mail_content =
str_replace('##firstname##',$fname,$mail_template);
Alexander Wagner> $mail_content =
str_replace('##lastname##',$lname,$mail_content);

Alexander Wagner> regards
Alexander Wagner> Wagner




-- 
Best regards,
 Richard  
mailto:[EMAIL PROTECTED]



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

2001-06-19 Thread Richard Kurth

Hello Alexander,
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. I do better when I can see complete examples to be
able to get the full picture

Monday, June 18, 2001, 4:01:45 PM, you wrote:

Alexander Wagner> Hiho,

Alexander Wagner> Richard Kurth wrote:
>> How can I add a variable to an e-mail on the fly. Say I have a form on
>> my page that the user fells in with data. but when he fills in the
>> message things like Hello,$Variable are added before it is sent. Does
>> this make sence

Alexander Wagner> Of course it does.
Alexander Wagner> However, variables are not the way to go. The mails are not parsed, 
so 
Alexander Wagner> variables won't do you any good. You'll have to use Placeholders. 
Something 
Alexander Wagner> like this:

Alexander Wagner> $mail_template = 
Alexander Wagner> "Hi ##firstname## ##lastname##,
Alexander Wagner> how are you...";

Alexander Wagner> Now you can continue with str_replace():
Alexander Wagner> $mail_content = str_replace('##firstname##',$fname,$mail_template);
Alexander Wagner> $mail_content = str_replace('##lastname##',$lname,$mail_content);

Alexander Wagner> regards
Alexander Wagner> Wagner




-- 
Best regards,
 Richard  
mailto:[EMAIL PROTECTED]