user1617426
user1617426

Reputation:

Configure Email Template Via Admin Panel

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

Answers (1)

Uday Sawant
Uday Sawant

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

Related Questions