diff --git a/admin/tool/messageinbound/classes/manager.php b/admin/tool/messageinbound/classes/manager.php
index a352f7c618d..fb0c04804bf 100644
--- a/admin/tool/messageinbound/classes/manager.php
+++ b/admin/tool/messageinbound/classes/manager.php
@@ -930,7 +930,7 @@ class manager {
$userfrom->customheaders[] = 'In-Reply-To: ' . $messageid;
// The message will be sent from the intended user.
- $eventdata->userfrom = \core_user::get_support_user();
+ $eventdata->userfrom = \core_user::get_noreply_user();
$eventdata->userto = $USER;
$eventdata->subject = $this->get_reply_subject($this->currentmessagedata->envelope->subject);
$eventdata->fullmessage = get_string('invalidrecipientdescription', 'tool_messageinbound', $this->currentmessagedata);
diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php
index 809cdb75d2c..76b25bca6eb 100644
--- a/enrol/paypal/ipn.php
+++ b/enrol/paypal/ipn.php
@@ -263,7 +263,7 @@ if (strlen($result) > 0) {
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
- $eventdata->userfrom = empty($teacher) ? core_user::get_support_user() : $teacher;
+ $eventdata->userfrom = empty($teacher) ? core_user::get_noreply_user() : $teacher;
$eventdata->userto = $user;
$eventdata->subject = get_string("enrolmentnew", 'enrol', $shortname);
$eventdata->fullmessage = get_string('welcometocoursetext', '', $a);
diff --git a/lang/en/auth.php b/lang/en/auth.php
index f540be787c2..0078fae7210 100644
--- a/lang/en/auth.php
+++ b/lang/en/auth.php
@@ -71,6 +71,8 @@ $string['emailupdatemessage'] = 'Dear {$a->fullname},
You have requested a change of your email address for your user account at {$a->site}. Please open the following URL in your browser in order to confirm this change.
+If you have any questions please contact support on: {$a->supportemail}
+
{$a->url}';
$string['emailupdatesuccess'] = 'Email address of user {$a->fullname} was successfully updated to {$a->email}.';
$string['emailupdatetitle'] = 'Confirmation of email update at {$a->site}';
diff --git a/lib/authlib.php b/lib/authlib.php
index 2d7405eb60d..a6fa7a09c31 100644
--- a/lib/authlib.php
+++ b/lib/authlib.php
@@ -762,8 +762,7 @@ function login_lock_account($user) {
$oldforcelang = force_current_language($user->lang);
$site = get_site();
- $supportuser = core_user::get_support_user();
-
+ $noreplyuser = core_user::get_noreply_user();
$data = new stdClass();
$data->firstname = $user->firstname;
$data->lastname = $user->lastname;
@@ -777,7 +776,7 @@ function login_lock_account($user) {
if ($message) {
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- email_to_user($user, $supportuser, $subject, $message);
+ email_to_user($user, $noreplyuser, $subject, $message);
}
force_current_language($oldforcelang);
diff --git a/lib/classes/task/send_failed_login_notifications_task.php b/lib/classes/task/send_failed_login_notifications_task.php
index a155baeb0d8..6f7e123c6c2 100644
--- a/lib/classes/task/send_failed_login_notifications_task.php
+++ b/lib/classes/task/send_failed_login_notifications_task.php
@@ -174,7 +174,7 @@ class send_failed_login_notifications_task extends scheduled_task {
mtrace('Emailing admins about '. $count .' failed login attempts');
foreach ($recip as $admin) {
// Emailing the admins directly rather than putting these through the messaging system.
- email_to_user($admin, \core_user::get_support_user(), $subject, $body);
+ email_to_user($admin, \core_user::get_noreply_user(), $subject, $body);
}
}
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index b9c10aebed9..8253d0e0cb3 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -5685,6 +5685,13 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
return true;
}
+ // Check from address and prevent emails to be sent from support email address.
+ $supportuser = core_user::get_support_user();
+ if ($from->email == $supportuser->email) {
+ debugging('Support user email address should not be used for email sending.', DEBUG_NORMAL);
+ return false;
+ }
+
if (email_should_be_diverted($user->email)) {
$subject = "[DIVERTED {$user->email}] $subject";
$user = clone($user);
@@ -5739,28 +5746,31 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
$temprecipients = array();
$tempreplyto = array();
- $supportuser = core_user::get_support_user();
-
// Make up an email address for handling bounces.
if (!empty($CFG->handlebounces)) {
$modargs = 'B'.base64_encode(pack('V', $user->id)).substr(md5($user->email), 0, 16);
$mail->Sender = generate_email_processing_address(0, $modargs);
} else {
- $mail->Sender = $supportuser->email;
+ $mail->Sender = $CFG->noreplyaddress;
}
- if (!empty($CFG->emailonlyfromnoreplyaddress)) {
+ // Email will be sent using no reply address.
+ if ($CFG->emailonlyfromnoreplyaddress == true) {
$usetrueaddress = false;
if (empty($replyto) && $from->maildisplay) {
$replyto = $from->email;
$replytoname = fullname($from);
}
+ } else {
+ // Use user's email address (if allowed).
+ $usetrueaddress = true;
}
if (is_string($from)) { // So we can pass whatever we want if there is need.
$mail->From = $CFG->noreplyaddress;
$mail->FromName = $from;
} else if ($usetrueaddress and $from->maildisplay) {
+ // If noreplyaddress is set to false, use users email address as from address.
$mail->From = $from->email;
$mail->FromName = fullname($from);
} else {
@@ -6005,7 +6015,7 @@ function setnew_password_and_mail($user, $fasthash = false) {
$site = get_site();
- $supportuser = core_user::get_support_user();
+ $noreplyuser = core_user::get_noreply_user();
$newpassword = generate_password();
@@ -6024,7 +6034,7 @@ function setnew_password_and_mail($user, $fasthash = false) {
$subject = format_string($site->fullname) .': '. (string)new lang_string('newusernewpasswordsubj', '', $a, $lang);
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message);
+ return email_to_user($user, $noreplyuser, $subject, $message);
}
@@ -6038,7 +6048,7 @@ function reset_password_and_mail($user) {
global $CFG;
$site = get_site();
- $supportuser = core_user::get_support_user();
+ $noreplyuser = core_user::get_noreply_user();
$userauth = get_auth_plugin($user->auth);
if (!$userauth->can_reset_password() or !is_enabled_auth($user->auth)) {
@@ -6068,7 +6078,7 @@ function reset_password_and_mail($user) {
unset_user_preference('create_password', $user); // Prevent cron from generating the password.
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message);
+ return email_to_user($user, $noreplyuser, $subject, $message);
}
/**
@@ -6081,7 +6091,7 @@ function send_confirmation_email($user) {
global $CFG;
$site = get_site();
- $supportuser = core_user::get_support_user();
+ $noreplyuser = core_user::get_noreply_user();
$data = new stdClass();
$data->firstname = fullname($user);
@@ -6099,7 +6109,7 @@ function send_confirmation_email($user) {
$user->mailformat = 1; // Always send HTML version as well.
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message, $messagehtml);
+ return email_to_user($user, $noreplyuser, $subject, $message, $messagehtml);
}
/**
@@ -6113,7 +6123,7 @@ function send_password_change_confirmation_email($user, $resetrecord) {
global $CFG;
$site = get_site();
- $supportuser = core_user::get_support_user();
+ $noreplyuser = core_user::get_noreply_user();
$pwresetmins = isset($CFG->pwresettime) ? floor($CFG->pwresettime / MINSECS) : 30;
$data = new stdClass();
@@ -6129,7 +6139,7 @@ function send_password_change_confirmation_email($user, $resetrecord) {
$subject = get_string('emailresetconfirmationsubject', '', format_string($site->fullname));
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message);
+ return email_to_user($user, $noreplyuser, $subject, $message);
}
@@ -6143,7 +6153,7 @@ function send_password_change_info($user) {
global $CFG;
$site = get_site();
- $supportuser = core_user::get_support_user();
+ $noreplyuser = core_user::get_noreply_user();
$systemcontext = context_system::instance();
$data = new stdClass();
@@ -6158,7 +6168,7 @@ function send_password_change_info($user) {
$message = get_string('emailpasswordchangeinfodisabled', '', $data);
$subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message);
+ return email_to_user($user, $noreplyuser, $subject, $message);
}
if ($userauth->can_change_password() and $userauth->change_password_url()) {
@@ -6179,7 +6189,7 @@ function send_password_change_info($user) {
}
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
- return email_to_user($user, $supportuser, $subject, $message);
+ return email_to_user($user, $noreplyuser, $subject, $message);
}
diff --git a/lib/tests/messagelib_test.php b/lib/tests/messagelib_test.php
index ecc3dc5ab48..f5641dd3e52 100644
--- a/lib/tests/messagelib_test.php
+++ b/lib/tests/messagelib_test.php
@@ -36,11 +36,11 @@ class core_messagelib_testcase extends advanced_testcase {
set_config($disableprovidersetting, 1, 'message');
$preferences = get_message_output_default_preferences();
$this->assertTrue($preferences->$disableprovidersetting == 1);
-
+ $noreplyuser = core_user::get_noreply_user();
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
- $message->userfrom = get_admin();
+ $message->userfrom = $noreplyuser->email;
$message->userto = $this->getDataGenerator()->create_user();;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
diff --git a/message/tests/messagelib_test.php b/message/tests/messagelib_test.php
index bbdaf8725fc..351a337015a 100644
--- a/message/tests/messagelib_test.php
+++ b/message/tests/messagelib_test.php
@@ -160,7 +160,6 @@ class core_message_messagelib_testcase extends advanced_testcase {
// Noreply user being valid user.
core_user::reset_internal_users();
$CFG->noreplyuserid = $user3->id;
- $noreplyuser = core_user::get_noreply_user();
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
$this->assertCount(0, $onlinecontacts);
$this->assertCount(1, $offlinecontacts);
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index ab4a4aee9f6..5ec8dceba3b 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -853,8 +853,8 @@ function forum_cron() {
$eventdata->set_additional_content('email', $additionalcontent);
}
- // If forum_replytouser is not set then send mail using the noreplyaddress.
- if (empty($CFG->forum_replytouser)) {
+ // If replytouser is not set then send mail using the noreplyaddress.
+ if (empty($CFG->noreplyaddress)) {
$eventdata->userfrom = core_user::get_noreply_user();
}
diff --git a/mod/forum/settings.php b/mod/forum/settings.php
index d2980f1ede1..9dc0762e5c4 100644
--- a/mod/forum/settings.php
+++ b/mod/forum/settings.php
@@ -29,9 +29,6 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configselect('forum_displaymode', get_string('displaymode', 'forum'),
get_string('configdisplaymode', 'forum'), FORUM_MODE_NESTED, forum_get_layout_modes()));
- $settings->add(new admin_setting_configcheckbox('forum_replytouser', get_string('replytouser', 'forum'),
- get_string('configreplytouser', 'forum'), 1));
-
// Less non-HTML characters than this is short
$settings->add(new admin_setting_configtext('forum_shortpost', get_string('shortpost', 'forum'),
get_string('configshortpost', 'forum'), 300, PARAM_INT));
diff --git a/mod/forum/upgrade.txt b/mod/forum/upgrade.txt
index 670541462fe..566a67fe455 100644
--- a/mod/forum/upgrade.txt
+++ b/mod/forum/upgrade.txt
@@ -2,6 +2,8 @@ This files describes API changes in /mod/forum/*,
information provided here is intended especially for developers.
=== 3.2 ===
+ * The setting $CFG->forum_replytouser has been deprecated in favour of a centralized noreplyaddress setting.
+ Please use $CFG->noreplyaddress setting instead.
* The following functions have been finally deprecated and should no longer be used.
- forum_count_unrated_posts
- forum_tp_count_discussion_read_records
diff --git a/user/edit.php b/user/edit.php
index 044522a76ca..8a18c4163eb 100644
--- a/user/edit.php
+++ b/user/edit.php
@@ -258,17 +258,20 @@ if ($usernew = $userform->get_data()) {
$tempuser = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
$tempuser->email = $usernew->preference_newemail;
+ $supportuser = core_user::get_support_user();
+
$a = new stdClass();
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
$a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID)));
$a->fullname = fullname($tempuser, true);
+ $a->supportemail = $supportuser->email;
$emailupdatemessage = get_string('emailupdatemessage', 'auth', $a);
$emailupdatetitle = get_string('emailupdatetitle', 'auth', $a);
// Email confirmation directly rather than using messaging so they will definitely get an email.
- $supportuser = core_user::get_support_user();
- if (!$mailresults = email_to_user($tempuser, $supportuser, $emailupdatetitle, $emailupdatemessage)) {
+ $noreplyuser = core_user::get_noreply_user();
+ if (!$mailresults = email_to_user($tempuser, $noreplyuser, $emailupdatetitle, $emailupdatemessage)) {
die("could not send email!");
}
}