Replace MYSQL result Varriable (email template)


I have made some email templates which are saved as text into a MYSQL database.

I want to use these to send emails from a php signup script etc.

How can I put a $variable into the email and get it to replace that with something when it sends the email,


Email template saved in DB:


Hello and welcome,

your login number is $login your password is $password.

bla bla ( a long email with lots of details and things pulled from db)


Email sent to user


Hello and welcome,

your login number is 1213254 your password is 3243242

bla bla ( a long email with lots of details and things pulled from db)


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AUCKLANDITAuthor Commented:
I have tryed a few things but the mysql result is just treated like plain text using mail (.

Also the reason for needing an email template saved into the database is for easy updating as it is quite long and will require updating often.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you will need to show how to pass the text from the db to the email function ...
A quick way is to use php eval function

$login = 'username';
$password = 'password';

eval("\$email_body = \"$template_from_db\";");

now use $email_body variable to send mail.

however there is a more safer way.

first update you email template in database and change $login and password with %login% and %password%
and then

$var_list = array('%login%, '%password%'');
$val_list = array($login, $password);

$email_body = str_replace($var_list, $val_list, $template_from_db);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AUCKLANDITAuthor Commented:
thanks heaps!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.