RE: [PHP] email templates and str_replace
| From: | Rich Cavanaugh | Date: | Wed, 20 Jun 2001 15:16:34 +0000 |
| Subject: | RE: [PHP] email templates and str_replace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54544@lists.php.net to get a copy of this message | ||
Richard,
The problem is with the str_replace()s. Consider the following:
<?php
$myvar = 'this is a var.';
$mytext = str_replace('is', 'is not', $myvar);
?>
At this point $myvar still equals 'this is a var.' but $mytext is 'this is
not a var.' $myvar hasn't been modfified by the str_replace so any
additional str_replace()s after it will not have a cumlative effect.
<?php
$mail_content = $mail_template;
$mail_content = str_replace('##fullname##',$fullname,$mail_content);
$mail_content = str_replace('##email##',$email,$mail_content);
$mail_content = str_replace('##domain##',$domainname,$mail_content);
?>
Something like the above would have the effect you're looking for.
--
Rich Cavanaugh
CTO, EnSpot.com
-----Original Message-----
From: Richard Kurth [mailto:rkurth@pacifier.com]
Sent: Wednesday, June 20, 2001 4:32 AM
To: php-general@lists.php.net
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