diff --git a/config-dist.php b/config-dist.php index 312e0f55ad4..4bbae13f956 100644 --- a/config-dist.php +++ b/config-dist.php @@ -364,6 +364,8 @@ $CFG->admin = 'admin'; // When working with production data on test servers, no emails should ever be send to real users // $CFG->noemailever = true; // +// Divert all outgoing emails to this address to test and debug emailing features +// $CFG->divertallemailsto = 'root@localhost.local'; // //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser diff --git a/lib/moodlelib.php b/lib/moodlelib.php index c25aa2af921..aabfa86870c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4207,6 +4207,12 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a return true; } + if (!empty($CFG->divertallemailsto)) { + $subject = "[DIVERTED {$user->email}] $subject"; + $user = clone($user); + $user->email = $CFG->divertallemailsto; + } + // skip mail to suspended users if (isset($user->auth) && $user->auth=='nologin') { return true;