• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Replace MYSQL result Varriable (email template)

Hello,

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,

eg.

Email template saved in DB:

Template
____________

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)

______________


0
AUCKLANDIT
Asked:
AUCKLANDIT
  • 2
1 Solution
 
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.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you will need to show how to pass the text from the db to the email function ...
0
 
nasirbestCommented:
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);
0
 
AUCKLANDITAuthor Commented:
thanks heaps!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now