Not receiving emails from php mail() function

December 1, 2016 5.7k views
Email PHP Ubuntu 16.04

I’m not receiving emails from mail() function.

I created a php test:

    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "";
    $to = "";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
$headers .= "Reply-To: $to";

The output is…


I’m using a LEMP droplet on Ubuntu 16.06. I already installed postfix, opened port 25 and checked my host file… localhost.crazytraction localhost amsterdam

which I think is correct (amsterdam is the hostname)

I can receive the email in one of my accounts, but I tried other 3 and none of them received the email, even Gmail is not receiving it.

What Am I doing wrong?

Btw, I tested to send an email using the same function on another droplet and it worked, so it has to be something with the environment, but I cannot figure what it is!

Thank you.

1 Answer

Your SPF record is invalid and you are not sending all the required headers an e-mail should have.

  • The headers are enough because I’m using the same script from another server and it works.
    I want to do the SPF, but saying is wrong doesn’t help too much. Could you be more specific?

Have another answer? Share your knowledge.