|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38091 Mail() does not use FQDN when sending SMTP helo
Submitted: 2006-07-13 09:28 UTC Modified: 2021-03-15 07:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: danb1974 at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Mail related
PHP Version: * OS: Windows
Private report: No CVE-ID: None
 [2006-07-13 09:28 UTC] danb1974 at gmail dot com
Computer reports "Full computer name: trashcan2.intranet" in my computer properties, computer name tab.

Sending mail using mail() functions generates a "helo trashcan2" instead of "helo trashcan2.intranet", which is rejected by a unforgiving smtp server (helo requires fqdn).

Reproduce code:
mail('', 'test', 'message')

Actual result:
Warning: mail(): SMTP server response: 504 <trashcan2>: Helo command rejected: need fully-qualified hostname in C:\Temp\php\test.php on line 6


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-13 14:32 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The host name use is the same one as your machine will report 
if you run ipconfig /all (Host Name value).
 [2006-07-14 06:23 UTC] danb1974 at gmail dot com
Ok now I'm confuzed.

* smtp requires helo to send fqdn and not just the hostname (it's stated somewhere in the rfc's)
* windows xp fqdn is what the computer reports as "full computer name" (at least so does some say, see
* a windows xp joined to a domain (a) does not give you any choice about the hostname, it's the computer name which is obviously not fqdn and (b) does report the correct name as "full computer name"
* on linux it works correctly (not using hostname but hostname -f value which is the fqdn)

So at this point it's basically "I cannot send mail from xp to an unforgiving mail server and yes it's a feature so I have to live with it"
 [2006-07-14 06:45 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The windows XP "feature" for domain name resolution 
apparently gives out a bogus answer. This is an XP bug, 
not a PHP bug. Additionally, "trashcan2.intranet" is not 
a FQDN. See: <>.
 [2006-07-14 07:45 UTC] danb1974 at gmail dot com
It seems it's not enough to just gethostname. You have to do something like this (this is not actual production code):

hostent *hent;
gethostname(hname, sizeof(hname));
hent = gethostbyname(hname);
strcpy(hostname, hent->h_name); // h_name is the official name according to winsock api
 [2009-06-20 08:53 UTC]
Reopen, seems to be still valid.
 [2009-06-22 13:52 UTC] rick at longbowgames dot com
This isn't really a bug in Windows, since the official documentation for Winsock[1] clearly states that the name returned by gethostname "can be a simple host name, or it can be a fully qualified domain name."  Like many parts of Winsock, this is slightly different from the typical behaviour of the POSIX function of the same name, which usually returns a FQDN.

Actually, while the name returned by gethostname() is *usually* a FQDN on a POSIX machine, I don't actually think it's guaranteed there, either.

For a C solution, the code given by danb1974 should work.  An easy way to do it in pure PHP is, instead of just calling gethostname(), call gethostbyaddr(gethostbyname(gethostname())).



 [2009-06-27 11:31 UTC]
Patch available at:
 [2009-06-30 11:40 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2009-06-30 11:55 UTC]
Temporary re-opened, as a reminder to cleanup the POSIX code in sendmail, the bug itself is fixed but the report will remain open until its converted
 [2010-10-22 14:17 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 20:01:27 2023 UTC