Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I wanted to be able to use the email address for a user making a booking within MRBS to send acknowledgements, confirmations etc.
I added this code within function_mail.inc and it works. The bit I inserted into the existing function is marked with comments at the beginning and end.
// get the email address of a user
// returns an empty string in the event of an error
function get_email_address($user)
{
global $mail_settings, $auth, $tbl_users, $ldap_get_user_email;
if ('db' == $auth['type'])
{
$email = sql_query1("SELECT email
FROM $tbl_users
WHERE name='" . addslashes($user) . "'
LIMIT 1");
if ($email == -1)
{
$email = "";
}
}
else if (('ldap' == $auth['type']) && $ldap_get_user_email)
{
$email = authLdapGetEmail($user);
}
// Inserted code for Drupal module ////////////////////////////
else if ('drupal' == $auth['type'])
{
//Connect to the Drupal database
$conn = sql_connect($auth['drupal']['db_system'],
$auth['drupal']['db_host'],
$auth['drupal']['db_username'],
$auth['drupal']['db_password'],
$auth['drupal']['db_name']);
$user = addslashes($user);
//we use default D7 table names here to take email address of the user
$drupal_email_query = "SELECT mail FROM dr_users WHERE name = '$user'";
$r_email = sql_query($drupal_email_query, $conn);
$row_email = sql_row($r_email, 0, $conn);
$email = $row_email[0];
}
// End of Inserted Code ////////////////////////////////////////////////////////////////////////////
else
{
$email = str_replace($mail_settings['username_suffix'], '', $user);
$email .= $mail_settings['domain'];
}
return $email;
}
I hope this can help other users.