How can I get a user's language from their e-mail address in PHP? I'm using the Mime Mail module to send HTML e-mails to my users.  I have created a template, mimemail-message.tpl.php, and placed it in my theme's directory.  This template defines header and footer links and is applied to every outgoing e-mail.

However, I have a multilingual site and I want to customize these footers per language.  My PHP skills are limited but I'm fairly confident I can do this with a switch statement if I can get the e-mail recipient's language.

I'm having trouble figuring out how to get the user's language.  The Mime Mail module provides a variable, $recipient, which is set to the e-mail address of the user.  Is it possible to load a user based on the e-mail address and then get the user's language?
I don't think there's an API function to do exactly that, but a single database query would get you that information:

// Query the database
$args = array(':email' =&gt; $email_address);
$lang = db_query('SELECT language FROM {users} WHERE mail = :email', $args)-&gt;fetchField();

// If there's no language string use LANGUAGE_UNDEFINED instead.
// This is also a fallback method to use the default language 
// if the user is not found in the database.
if (!$lang || empty($lang)) {
  $lang = LANGUAGE_UNDEFINED; // Or whatever your default language is
}


If you need the user object itself for whatever reason, you can use a slight variation on the above:

$args = array(':email' =&gt; $email_address);
$uid = db_query('SELECT uid FROM {users} WHERE mail = :email', $args)-&gt;fetchField();

if ($uid) {
  $account = user_load($uid);
  $lang = $account-&gt;language;
}


You could also take advantage of the $conditions parameter of user_load_multiple(), but this method has been deprecated so it might not be the best idea to use it:

$users = user_load_multiple(array(), array('mail' =&gt; $email_address));
if (!empty($users)) {
  $account = array_shift($users);
  $lang = $account-&gt;language;
}


Last but not least, you could use an EntityFieldQuery, although this would probably be overkill for this particular task. It is a useful thing to know though:

$query = new EntityFieldQuery;
$query-&gt;entityCondition('entity_type', 'user')
  -&gt;propertyCondition('mail', $email_address);

$results = $query-&gt;execute();
if (isset($results['user'])) {
  $users = user_load_multiple(array_keys($results['user']));
  if (!empty($users)) {
    $account = array_shift($users);
    $lang = $account-&gt;language;
  }
}