Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6740311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:35:28+00:00 2026-05-26T11:35:28+00:00

I have mail template on different languages, and inside this templates some php variables

  • 0

I have mail template on different languages, and inside this templates some php variables are using. I have to store templates in DB and before sending a mail, receive template for current language and replace all php vars. While I was doing this with the help of views – there was no probles, but now I don’t know how to replace php vars in template?
Or maybe there is the better way to solve this problem? I just need to have the ability to edit templates from admin side.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:35:28+00:00Added an answer on May 26, 2026 at 11:35 am

    Why don’t you store the variables in the email template as something non-PHP e.g..

    Thank you %name% for registering!
    

    This makes it easy for admin editing.

    Then in your code before you send you have an array of all variables to replace…

    $template = $this->load->view('email_template.html', '', true);
    
    foreach ($vars as $key => $value) {
        $template = str_replace('%' . $key . '%', $value, $template);
    }
    

    Edit

    In response to your comment below I would setup the languages in an array and then use PHP in the view to output the correct language, then do the replacement…

    // 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);
    }
    

    email_template.html

    <html>
    <body>
        <p><?php echo $messages[$lang]['thank_you']; ?></p>
        <hr />
        <p><?php echo $messages[$lang]['username_details']; ?></p>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with e-mail templates. I have an html template with three embedded
I have an HTML Mail template, with a place holder for the image. I
I have an e-mail template which is just a plain, static HTML page. I
I have this mail script I have to run a few times. To start
Is there some way to have the Mail Merge capability in my application? Maybe
I have a php mail script sitting on a LAMP vps server. The script
I'm using http://code.google.com/p/django-email-extras/ to generate rich email content. I have trouble in sending email
my mail have some tempalte with HTML tags includes and images.. when i am
I have written a mail-processing program, which basically slaps a template on incoming mail
I have a template that has some Javascript used to generate graphs in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.