PHPMailer::serverHostname PHP Method

serverHostname() protected method

Returns 'localhost.localdomain' if unknown.
protected serverHostname ( ) : string
return string
    protected function serverHostname()
    {
        $result = 'localhost.localdomain';
        if (!empty($this->Hostname)) {
            $result = $this->Hostname;
        } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
            $result = $_SERVER['SERVER_NAME'];
        } elseif (function_exists('gethostname') && gethostname() !== false) {
            $result = gethostname();
        } elseif (php_uname('n') !== false) {
            $result = php_uname('n');
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * 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;
 }