Re: email templates and str_replace

From: Date: Wed, 20 Jun 2001 13:43:00 +0000
Subject: Re: email templates and str_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-54515@lists.php.net to get a copy of this message
Mr. Kurth, Try this. Save the mail template to another file [like mailtemplate.txt] then open it for reading. //read in template $template = file("mailtemplate.txt"); //setup variables $fullname="Richard Kurth"; $email="rkurth@pacifier.com"; $hostdomain="northwesthost.com"; $hostname="www"; $domain="twohot"; $tld=".com"; $baseip="234.444.45.444"; $username="rkurth"; $password="boat"; $userdatabase="twohot"; $newuser="twohot"; $newuserpass="twohot"; $sales="sales"; $domainname=$hostname . "." . $domain . $tld; //iterate through the template replacing the items for($i = 0; $i < sizeof($template); $i++) { $template[i] = str_replace('##fullname##',$fullname,$template[i]); $template[i] = str_replace('##email##',$email,$template[i]); $template[i] = str_replace('##domain##',$domainname,$template[i]); $template[i] = str_replace('##ip##',$baseip,$template[i]); $template[i] = str_replace('##username##',$username,$template[i]); $template[i] = str_replace('##password##',$password,$template[i]); $template[i] = str_replace('##userdatabase##',$userdatabase,$template[i]); $template[i] = str_replace('##newuser##',$newuser,$template[i]); $template[i] = str_replace('##newuserpass##',$newuserpass,$template[i]); $template[i] = str_replace('##hostdomain##',$hostdomain,$template[i]); $template[i] = str_replace('##sales##',$sales,$template[i]); } //Now the array $template contains our message, parsed and all //from here we can implode it into one string, or we can leave //it be to do further things to it. The example from above is //similar to the method I use in my TemplateEngine I wrote a //little while back, I might just include the source some time. Hope this helps, Chris "TunkeyMicket" Watford -------------------------------------------- TunkeyMicket Productions www.tunkeymicket.com ----- Original Message ----- From: "Richard Kurth" <rkurth@pacifier.com> To: <php-general@lists.php.net> Sent: Wednesday, June 20, 2001 4:32 AM Subject: [PHP] email templates and str_replace > I am trying to set up a template for an email program below you will > see the test program the $mail_template is pulled from a database > that is pre saved when it is saved the Placeholders are filled in > using str_replace. that is what I want it to do. But it does not work. What am > I missing hear. > > $mail_template= "<html> > <head> > <title>Web Hosting At ##hostdomain## </title> > </head> > > <body bgcolor='#C4C9DB'> > <font size='4' color='#008080'><strong>Dear ##fullname## > </strong></font> > <br><br> > <font size='4' color='#008080'><strong>Your webhosting account > has been created. Please use the following data to log in to ##domain## </strong></font> > <br> > <font size='4' color='#008080'> > <strong><ul type=square> > <li>Domain:##domain## </li> > <li>IP-Address: ##ip## </li> > <li>Username: ##username##</li> > <li>Password: ##password##</li> > <li>Mysql Database: ##userdatabase## </li> > <li>Mysql Username: ##newuser## </li> > <li>Mysql Password: ##newuserpass## </li> > </ul> </strong> > </font> > > <font size='4' color='#008080'><strong>Thanks for choosing > ##hostdomain## <br> Any Questions e-mail ##sales##@##hostdomain##</strong> </font> > > </body> > </html> > "; > > /* message*/ > //$mail_template = $message; > > $fullname="Richard Kurth"; > $email="rkurth@pacifier.com"; > $hostdomain="northwesthost.com"; > $hostname="www"; > $domain="twohot"; > $tld=".com"; > $baseip="234.444.45.444"; > $username="rkurth"; > $password="boat"; > $userdatabase="twohot"; > $newuser="twohot"; > $newuserpass="twohot"; > $sales="sales"; > $domainname=$hostname . "." . $domain . $tld; > > > $mail_content = str_replace('##fullname##',$fullname,$mail_template); > $mail_content = str_replace('##email##',$email,$mail_template); > $mail_content = str_replace('##domain##',$domainname,$mail_template); > $mail_content = str_replace('##ip##',$baseip,$mail_template); > $mail_content = str_replace('##username##',$username,$mail_template); > $mail_content = str_replace('##password##',$password,$mail_template); > $mail_content = str_replace('##userdatabase##',$userdatabase,$mail_template); > $mail_content = str_replace('##newuser##',$newuser,$mail_template); > $mail_content = str_replace('##newuserpass##',$newuserpass,$mail_template); > $mail_content = str_replace('##hostdomain##',$hostdomain,$mail_template); > $mail_content = str_replace('##sales##',$sales,$mail_template); > /* and now mail it */ > /* recipients */ > $recipient = "$fullname <$email>" ; > //header > $headers .="From: Sales Department < rkurth@northwesthost.com \n>"; > $headers .= "reply-To:$from\nX-Mailer: PHP/" .phpversion()." \n"; > $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; > //subject > $subject1 = $subject; > //mail($recipient, $subject1, $mail_content, $headers); > //print "$recipient, $subject1, $mail_content, $headers"; > echo $mail_content; > > > > > > > > > > > > Best regards, > Richard > mailto:rkurth@pacifier.com

« previous php.general (#54515) next »