How to send e-mail in users selected languages I have created two users and my site supported two languages(English,Spanish).
In every 5 hours CRON will be run,I have wrote a custom module and every CRON run users are getting Emails thats fine.
But here is the problem is Emails are not sended to users prefered languages,it takes admin default language and sended to users.


I have installled multilingual module also.

I want Emails should be in users prefered languages only.

Code:-

function sendmail($from, $to, $firstname, $message, $user,$language) {
  $module = "my_mail_example";
  $key = "mail_example";
  $language = user_preferred_language();
  $send = TRUE;
  $params = array(
    'body' =&gt; $message,
    'subject' =&gt; 'Hello from Bright Ideas'
  );
  $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);  
  $current_messages = $user -&gt; field_reminder_messages_received[LANGUAGE_NONE][0]['value'];
  $updated_messages = $current_messages.'\r\n'.$logmessage;  
  $edit = array(
      'field_reminder_messages_received' =&gt; array(LANGUAGE_NONE =&gt; array(0 =&gt; array('value' =&gt; $updated_messages, ), ), ),
    );
  user_save($user, $edit);  
}
Cron runs as the anonymous user, so any emails sent by cron will use the site's default language.

Your code snippet has the following:

 $language = user_preferred_language();


This is wrong.  It will get the preferred language of the anonymous user, not the user you're sending the mail to.

Instead: figure out the recipient's preferred language:

$userobj = user_load($user);
$language = user_preferred_language($userobj);


Now, you can send mail with the correct language:

$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);