0

We have multilingual site pointing to 2 domain according to site language.

www.example.com (Swedish)

www.other.com (English)

Now when some user post content from Swedish domain we want to send notification of content submission to user from info@example.com and if from English domain then from info@other.com

Is that possible ?

I have attempted like below in custom module whose weight is 1000:

function custom_overrides_init() {

  global $language;

  if($language->language == "sv"){
    variable_set('site_mail', "info@example.com");
  }else if($language->language == "en"){
    variable_set('site_mail', "info@other.com");
  }
}

When I see in maillog it shows correct from email addresse but its not working and use same email address which is set on site configuration.

i18n_variable also does not provide site_email as variable.

Please suggest !

  • Well, I don't have time to write the whole answer, so here is a comment to help you. The solution you are using (with hook_init) will not work in a production website, because if two visitors open a page at the same time there will be a problem. So, as you have a custom module, you can implement hook_variable_info or hook_variable_info_alter from variable module to add the translation option to site_mail variable. – juankvillegas Oct 12 '16 at 15:22
  • @juankvillegas thanks! I have tired but it does not seems to work. That will be helpful if you can provide some demo code when you have time :) – jas Oct 13 '16 at 6:53
1

Your current solution is actually a very bad practice, as you will be rebuilding the variable cache on every page request, which is a big hit.

You can set the site_mail variable as translatable by installing the Variable module (http://dgo.to/variable), then implementing hook_variable_info() and declaring the site_mail variable.

function hook_variable()
{
  $variables['site_mail'] = array
  (
    'title' => t('Site Email'),
    'description' => t('The email addresses site mails are sent from'),
    'type' => 'string',
  );

  return $variables;
}

You then need to go to Admin -> Configuration -> Regional and Language -> Mutilingual settings -> Variables, and set site_mail as being translatable. You will then be able to visit the site information page and set a different value for the site mail in each language.

  • Now I can set separate email for separate languages. But still the default language site_mail is used to send emails. Please suggest if we need to do something else to make it use site email according to language ? – jas Oct 17 '16 at 8:09
  • Just writing to confirm that site_email varibales is now multilingual and now I can add separate emails according to language but when it emails are sent out it does not use separate emails, do we need to do some additional work ? please suggest ! + 1 for help so far thanks! – jas Oct 17 '16 at 11:28
  • That is because it is site email, not language email. If you need a per language email then one could create another variable, not to translate the site_email. As I stated in my answer, if the module Domain Access would be used, together with the Domain Variable module, then a site_email variable per domain would exist. No need for custom coding. – Emil Carpenter Oct 17 '16 at 16:58
0

Two different questions are asked,

  1. One question in the header:

Is it possible to make site_email an i18n variable?

This is probably not what you want.

  1. Another question in the text body:

Now when some user post content from Swedish domain we want to send notification of content submission to user from info@example.com and if from English domain then from info@other.com

Is that possible ?

Yes, it is possible and it is about domains as you state in this question (not languages).

The Domain Variable module should be used together with the Domain Access module. These modules make the site_email as a variable per each domain. No custom coding needed.

You could then have these site emails:

  • noreply@sweden.com (as sender for all languages on www.sweden.com)
  • noreply@worldwide.com (as sender for all languages on www.worldwide.com)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.