Hello All,
I'm not sure if I'm even on the right track here but this is what I'm trying to do.
I have a db with user information and email templates. The template would look something like this
Dear <Name> or <NickName>
Thanks for joining us at <sitetitle> at
<url>
Your Password is <password> and login name is <NickName>
Best regards
<adminname>
We will say everthing in bold above = $sw_mail["mail"]
$m = new Mail; // create the mail
$m->From( $sw_mail["fromid"] );
$m->To( $member_arr["sb_email"] );
$m->Subject( $sw_mail["subject"] );
$message = str_replace("<email>",$member_arr["sb_email"],
str_replace("<username>",$member_arr["sb_username"],
str_replace("<password>",$member_arr["sb_pwd"],
$sw_mail["mail"]
)));
$message = str_replace("<title>",$null_char,
str_replace("<url>",$null_char,
str_replace("<reciprocallink>",$null_char,
str_replace("<urldescription>",$null_char,
str_replace("<category>",$null_char,
$message
)))));
$m->Body( $message ); // set the body
$m->Priority( 1 ) ; // set the priority to high
$m->Send(); //-- send message
I didn't want to write a custom str_replace for EACH mail type i.e. $sw_mail["mail"] since there are about 20 different mails that can go out.
How about a function to it and I started doing something like this but then realized that if I have array 1 contains items <username> and array two contians my vars like "$member_arr["sb_username"]"
then the arrays will be different sizes and to further confuse me they would not be in the same order at all.
Here is the function I started
function string_replace( $content,$var_array )
{
$replace_array['<username>'] = '<username>';
$replace_array['<password>'] = '<password>';
$replace_array['<email>'] = '<email>';
$replace_array['<title>'] = '<url>';
$replace_array['<reciprocallink>'] = '<reciprocallink>';
$replace_array['<urldescription>'] = '<urldescription>';
$replace_array['<category>'] = '<category>';
//ksort($cuss_array);
//ksort($fruits);
foreach ( $replace_array as $replaceword=>$var_array )
{
$content_new = preg_replace("$replaceword", "$var_array", "$content");
}
return $content_new;
}
I thought I could just do something like
$var_array['<username>'] = $member_arr["sb_username"];
$var_array['<password>'] = $member_arr["sb_password"];
string_replace($message,$var_array )
Then I would place the above function and array assignment before
$m->Body( $message );
Basically I want a long list of static items I want replaces, then I want to generate a small custom list of times and I was trying to write a function to automate this so all I do is pass what I want replaced and the message and it would return the message with names, passwords etc... then send it.
Hopefully someone here will understand what I'm trying to do.
Thanks for any help, OH, I thought an associative array would be the way to go but I just don't know.
My goal I guess is to get rid of the current $message handling so it doesn't get so messy since it goes on a lot of other pages too