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 8262109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:39:12+00:00 2026-06-08T03:39:12+00:00

Sorry if the title is not enough clear, I didn’t know how to write

  • 0

Sorry if the title is not enough clear, I didn’t know how to write it better.

The situation is that I a have a cron job that sends mails to users. I have language files, and depending in the configuration of the user I want to send the mail in his language.

But I don’t know how to do this.

Each language file have constants definitions like:

en.php define(‘DATE’,’Date’); define(‘TIME’,’Time’);

es.php define(‘DATE’,’Fecha’); define(‘TIME’,’Hora’);

And I need to display the correct labels depending the user language, but I’m in a while loop:

while ($row = mysql_fetch_array($res)) {
   if ($row['lang'] == en) //load the english labels 
}

So I think I can’t use something like "include_once" in each iteration.

  • 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-06-08T03:39:16+00:00Added an answer on June 8, 2026 at 3:39 am

    The problem is that you use PHP Constants for it so once they are set, you can’t really change them within the script. Try to rewrite your constants and all references of them into variables.

    Let’s say that your language files are named like this lang.code.php and the script that will send the email is in sendemail.php. You can do something like this:

    In lang.en.php
    <?php
      $terms['date'] = 'Date';
    
    
    In lang.es.php
    <?php
      $terms['date'] = 'Fecha';
    
    
    In sendemail.php:
    <?php
      function sendEmail($language = 'en')
      {
        include "lang.$language.php";
        extract($terms);
        $to = 'foo@bar.com';
        $subject = 'Test';
        $body = "The $date today is: " . date('r');
        mail(...);
      }
    
      foreach($users as $user)
        sendEmail($user->preferredLanguage);
    

    You can then reference terms in your language files using their keys in the $terms array. Of course you’d have to create validation checks for the language files, directory traversals, etc. But that’s one way to implement it.

    If you can’t rewrite your code then I suggest putting all of the email contents in one file and use file_get_contents() to fetch the email content via HTTP. Inside that file, you’d have a conditional which loads the language file you need.

    Let’s say that the file that will generate the email contents is called emailcontent.php, you can do something like this:

    In lang.en.php
    <?php
      define('DATE', 'Date');
    
    
    In lang.es.php
    <?php
      define('DATE, 'Fecha');
    
    In emailcontent.php
    <?php
      require "lang.{$_GET['lang']}.php";
    
      echo 'The ' . DATE . ' today is: ' . date('r');
    
    
    In sendemail.php
    <?php
    
      $to = 'foo@bar.com';
      $subject = 'Test';
    
      foreach($users as $user)
      {
        $contents = file_get_contents('http://yourhost.com/emailcontent.php?lang=en');
        mail(...); 
      }
    

    Of course you need to add some security checks to prevent local file inclusion, access to emailcontent.php, etc. But this is the gist of it. However this has a big overhead in terms of latency and repeated compilation of your PHP code. If there was any other way to clear the global score for each email, then that is the better way to go. But this is the only way I can think of if you can’t rewrite your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the title is not clear enough, I have <a> elements with the
Sorry the title may not be very clear. Basically I have a wrapper for
Sorry if the title is not that specific, but I don't know how else
So I am not sure if my title is clear enough. I essentially have
Sorry in advance for those who find that my title is not precise enough.
Didn't know how to word the title sorry. Basically I have a comments system,
Sorry for the title, perhaps it's not very clear. I have some SQL queries
Sorry the title is not very clear. This is a follow up to my
I am sorry for the title but I really do not know how to
First of all, sorry about that title. I'm not the best at writing those

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.