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.
This commit is contained in:
Andrew Nicols
2015-01-30 11:01:11 +08:00
parent cccb0c0722
commit 40c809b83e
+18
View File
@@ -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;
}
}