If you have creating email templates use this.
function Merge_template($message,$temparray) // merging function.
{
$melen=strlen($message);
$k=0;
for($j=0;$j<$melen;)
{
if($message[$j]=='#' && $message[$j+1]=='#')
{
$j=$j+2;
while($message[$j] != '#')
{
$test=$test.$message[$j];
$j++;
}
$pattern[$k]=$test;
$test='';
$k++;
}
$j++;
}
$length=count($temparray);
$i=0;
$outputtem=$message;
while($i<$length)
{
$pattern[$i];
$replacement=$temparray[$pattern[$i]];
$test= '/##'.$pattern[$i].'#/';
$outputtem=preg_replace($test,$replacement,$outputtem);
$i++;
}
return $outputtem;
}
$message = "The following account status changed by ##staffname#. Please take necessary action.
##description#
Reference No: ##ref_no#
Customer Name: ##customer_name#
Date : ##date#";
$date=date("d-m-Y");
$staffname="Thomas";
$description = " Test Description";
$ref_no = "238764";
$customer_name="Arnold";
$temparray=array("date"=>$date,"staffname"=>$staffname,
"description"=>$description,"ref_no"=>$ref_no,"customer_name"=>$customer_name);
$mail_body= Merge_template($message,$temparray);
?>
Output
The following account status changed by Thomas. Please take necessary action.
Test Description
Reference No: 238764
Customer Name: Arnold
Date : 17-12-2007
No comments:
Post a Comment