Re: An elegant way to send "generic" email messages

From: Date: Fri, 10 Nov 2000 15:43:02 +0000
Subject: Re: An elegant way to send "generic" email messages
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24660@lists.php.net to get a copy of this message
This would work... <? $lastpurchasedate = "10/1/2000"; $percentdiscount = "10"; $yourname = "Person"; $cutoffdate = "12/23/2000"; $f = fopen("ex1.txt","r"); $temp = fread($f,filesize("ex1.txt")); fclose($f); $a = eval($temp); echo $a; ?> ex1.txt file: print <<<EOF Hello $yourname You are getting this email because we think you're great. We appreciate your purchase of $lastpurchasedate and would like to offer you a $percentdiscount % discount if you place another order before $cutoffdate. Thanks! EOF ?> Notice the ?> as the last line in ex1.txt. Not sure why this is needed, but I can't eval() without it - I get errors (4.0.2). And there's no <? in the start of ex1.txt either. Perhaps I'm just missing something, but that's weird to me. Anyway, the above works, and would allow you a 'template' system for your emails, fairly independant of the PHP code. "Nebbe, Joelle" wrote: > Hello all > > Most web apps need to send confirmation emails, or welcome emails, or other > forms of generic email messages. > By generic I mean a message that is only customised by a few variables, i.e. > name and email address and maybe a specific link or ID. > > Now most examples of php I have ever seen always seem to build those > messages in the code. This is not really an acceptable solution as it is > usually not the developer who writes the text of the message but the same > people who work on the wording of the content of the site, or maybe the > designer i.e. people you don't want to allow free access to your php code. > > Now with html documents and templates this is easy, as you can use bits of > php code <?php echo $thisvariable ?> in your templates and call them through > include, or use one of the simple templating schemes. These don't work with > email as I don't want the result to go to the default output but to a > variable that will be the message body. > > What I want is the equivalent of <<<Eof but with an external file. > > So what's left? > 1. the manual parse/replace approach (i.e. read the file, replace every > ##variable## by $variable and plug the result in $message) > 2. put the email message in a php routine after all, and have to edit it > every single time someone decides that "greetings" is better than "hello" > after all. > > Is there not a more elegant way? I cannot help but think I'm overlooking > something > > Joelle Nebbe > > _______________________________________________________________________ > Any opinions expressed in the email are those of the individual and not > necessarily the company. This email and any files transmitted with it > are confidential and solely for the use of the intended recipient. > > If you are not the intended recipient or the person responsible for > delivering to the intended recipient, be advised that you have received > this email in error and that any use is strictly prohibited. > > If you have received this email in error please notify the IT manager > by telephone on 0113 243 2701 > _______________________________________________________________________ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- ========================== Michael Kimsal http://www.tapinternet.com 734-480-9961

« previous php.general (#24660) next »