From 40c809b83e9487b6adfedfdb7141c2d265a7c208 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 21 Jan 2015 14:35:30 +0800 Subject: [PATCH] MDL-48899 lib: Use the wwwroot to inform the message-ID PHPMailer can sometimes fail to get a valid hostname when trying to determine a Message-ID. Rather than relying entirely on the serverHostname, fall back on the wwwroot when unable to determine the real hostname. --- lib/phpmailer/moodle_phpmailer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/phpmailer/moodle_phpmailer.php b/lib/phpmailer/moodle_phpmailer.php index d58da430415..1ff22c6c6eb 100644 --- a/lib/phpmailer/moodle_phpmailer.php +++ b/lib/phpmailer/moodle_phpmailer.php @@ -162,4 +162,22 @@ class moodle_phpmailer extends PHPMailer { return parent::postSend(); } } + + /** + * Get the server hostname. + * Returns the host part of the wwwroot. + * + * @access protected + * @return string + */ + protected function serverHostname() { + global $CFG; + + $hostname = parent::serverHostname(); + if ($hostname === 'localhost.localdomain') { + $urlinfo = parse_url($CFG->wwwroot); + $hostname = $urlinfo['host']; + } + return $hostname; + } }