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

How to fix?


When a mail is sent via SMTP, the connecting server identifies itself via the HELO command. See https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol#SMTP_transport_example

You need to change this in the configuration settings for the smtp client. For sendmail specifically, there's an example here: https://serverfault.com/questions/205271/how-to-specify-outgoing-helo-with-sendmail

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.