Reputation:
I am currently developing an online bus ticket booking system.
I have given an option to configure email
template, but if I need to send the name of the customer I have inserted $username
in the email
template textarea
and saved it to mysql
database.
And when sending the email
I have retrieved the email template
from mysql db before the email script run's.
When I get the email, I am getting the customer name $username
. How can this be solved?
Upvotes: 1
Views: 262
Reputation: 5798
Save your email template like this
This is the :userName
Then in your script. retrieve the template
from DB
and then use str_replace
to replace
placeholder :userName
with the value in $username
$mailText = str_replace(':userName', $username, $templateFromDb);
If you need to replace more than 1 items use this
$str = "
Name -: :name
Address -: :address
DOB -: :dob
email -: :email";
$search = array(':name',':address',':dob',':email');
$replace = array($name,$address,$dob,$email);
$mailText = str_replace($search, $replace, $str);
Upvotes: 1