I have a DigitalOcean server which runs Ubuntu 14.04. I am having problems with sending emails from the PHP mail() function (which uses sendmail internally).

I think the issue may be related to my hosts file config. Here is what I have in /etc/hosts at the moment: localhost localhost.localdomain ip-xxx-xxx-xxx-xxx

And in etc/hostname:


(In the above two, I replaced the IP address digits with x)

Now I have a domain pointing to this server, let's call this mydomain.com.

So when my website mydomain.com sends an email, the email is going in to the junk mail folder. I ran a test on https://www.mail-tester.com and one of the issues it flags up is:

enter image description here

I have tried adding mydomain.com to the line above in the hosts file but this results in the email arriving after a long time or not arriving at all.

Here are the Received headers:

Received: from localhost.localdomain (unknown [xxx.xxx.xxx.xxx])
    (using TLSv1.2 with cipher xxx (256/256 bits))
    (No client certificate requested)
    by mail-tester.com (Postfix) with ESMTPS id xxx
    for <test-xxx@mail-tester.com>; Mon, 29 Apr 2019 18:35:18 +0200 (CEST)

Received: from localhost.localdomain (localhost [])
    by localhost.localdomain (8.15.2/8.15.2/Debian-3) with ESMTP id xxx
    for <test-xxx@mail-tester.com>; Mon, 29 Apr 2019 17:35:18 +0100

Received: from mydomain.com (www-data@localhost)
    by localhost.localdomain (8.15.2/8.15.2/Submit) with SMTP id xxx
    for <test-xxx@mail-tester.com>; Mon, 29 Apr 2019 17:35:18 +0100

Can someone please advise what the issue may be and how to fix?


Nobody cares about hops inside your infrastructure and how many localhosts are passed. But be sure to let your outgoing server say "Hello, I'm mail.domain.tld" instead of "Hello, I'm localhost.localdomain", because no halfway properly configured server will be interested to talk to unknown mailservers.

I see in your referenced headers that you use postfix(1) for processing outbound emails. Look for the variable myhostname inside your main.cf (usually located in /etc/postfix or /usr/local/etc/postfix) and fill it properly. Example: myhostname=mail.domain.tld (replace it with your mailservers name). Also be sure that smtp_banner= contains at least $myhostname like smtp_banner=$myhostname ESMTP Postfix.

See this for additional info.

| improve this answer | |
  • Hi Florian, thanks for your answer. I don't intentionally use Postfix - at one point I did have Postfix installed on the server but then I removed it as I no longer needed it. It seems it was not fully removed and is still being referenced somewhere. This is probably one of the causes of the issue. I only want to use sendmail. Do you know how I can fix this? – GSTAR May 9 '19 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.