I've mail template on different languages, and inside this templates some php variables are utilizing. I must store templates in DB and before delivering a mail, receive template for current language and replace all php vars. As I was carrying this out with the aid of sights - there is no probles, however I'm not sure how you can replace php vars in template? Or possibly there's the greater method to solve this issue? I simply need to be capable of edit templates from admin side.

Why not keep variables within the email template as something non-PHP e.g..

Thank you %name% for registering!

This causes it to be simple for admin editing.

Then inside your code if you possess an variety of all variables to exchange...

$template = $this->load->view('email_template.html', '', true);

foreach ($vars as $key => $value) {
    $template = str_replace('%' . $key . '%', $value, $template);


In reaction for your comment below I'd setup the languages in a wide array after which use PHP within the view to output the right language, then perform the alternative...

// List of message translations
$messages = array(
    'en' => array(
        'thank_you' => 'Thank you %name% for registering!',
        'username_details' => 'Your username is %username%'
    'fr' => array(
        'thank_you' => 'Merci %name% de l\'enregistrement!',
        'username_details' => 'Votre username est %username%'

// Variables to replace
$vars = array(
    'name' => 'John Smith',
    'username' => 'john'

// Choose language
$lang = 'en';

// Load the template
$template = $this->load->view('email_template.html', array('messages' => $messages, 'lang' => $lang), true);

// Replace the variables
foreach ($vars as $key => $value) {
    $template = str_replace('%' . $key . '%', $value, $template);


    <p><?php echo $messages[$lang]['thank_you']; ?></p>
    <hr />
    <p><?php echo $messages[$lang]['username_details']; ?></p>