Problem:
Message defaults are drawn from mdl_user_preferences, however they don't exist there until a user saves changes. Messages are supposed to be emailed by default when users are offline, however the code actually looks for the setting in mdl_usr_preferences, and then defaults to not sending messages until this preference is created.
Also, messaging creates an entry for the users email address in the mdl_user_preferences table, and only after the settings are saved. This creates the situation where users may have one email in mdl_user and another in mdl_user_preferences.
This is a significant problem as users expect messages to be emailed by default, as that is what the default settings in the settings form are set to do (email by default and to the users's email address as set in mdl_user), however these settings don't actually get created and used until the user clicks 'save changes' in the message settings form.
We attached a patch for lib.php fixes the problem by default to sending messages, and using the email settings in mdl_user to initial bug report for message email problems: .
I asked Mark Nielson to fix this, see below.
I put a patch in the bug tracker for bug 4639. This fixes the problem with messages not being emailed by default, and gets the email address from mdl_user.
Around line 990:
// Bug 4639 Fix Here
if (!isset($preference->message_emailmessages) or $preference->message_emailmessages) { // Receiver wants mail forwarding
// Bug 4639 Fix Here
if (!isset($preference->message_emailtimenosee)) {
$preference->message_emailtimenosee = 10;
}
if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough
$message = stripslashes_safe($message);
$tagline = get_string('emailtagline', 'message', $SITE->shortname);
$messagesubject = message_shorten_message(strip_tags($message), 30).'...';
$messagetext = format_text_email($message, $format).
"\n\n--\n".$tagline."\n"."$CFG->wwwroot/message/index.php?popup=1";
if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
$messagehtml = format_text($message, $format);
$messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
} else {
$messagehtml = NULL;
}
// Bug 4639 Fix Here
if (!empty($preference->message_emailaddress)) {
$userto->email = $preference->message_emailaddress; // Use custom messaging address
}
email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml);
}
}