Skip to content

Commit

Permalink
Ensure mail-wrapper.php use FQDN for hostname (#2805)
Browse files Browse the repository at this point in the history
* Support ensure it output the FQDN for hostname

* Make detection more feature proof

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
  • Loading branch information
clarkchentw and jaapmarcus committed Aug 3, 2022
1 parent eca25ef commit f975eab
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions web/inc/mail-wrapper.php
Expand Up @@ -25,8 +25,26 @@
$_SESSION['language'] = 'en';
}

// Define vars
$from = 'noreply@'.gethostname();
//define vars
//make hostname detection a bit more feature proof
$hostname = (function():string{
$badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
$ret = gethostname();
if(in_array($ret, $badValues, true)){
throw new Exception('gethostname() failed');
}
$ret2 = gethostbyname($ret);
if(in_array($ret2, $badValues, true)){
return $ret;
}
$ret3 = gethostbyaddr($ret2);
if(in_array($ret3, $badValues, true)){
return $ret2;
}
return $ret3;
})();

$from = 'noreply@'.$hostname;
$from_name = _('Hestia Control Panel');
$to = $argv[3]."\n";
$subject = $argv[2]."\n";
Expand Down

0 comments on commit f975eab

Please sign in to comment.