Ubuntu 14.04 mail() dont send email

June 14, 2016 225 views
Apache PHP Email DNS

Let´s go, I have PHP5 with apache2 installed in my Ubuntu 14.04 x64 with 512MB.

Great, I have a php file inside my server that execute this code below:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: ". "help@mysitecom". "\r\n";
$headers .= "Reply-To: ". "". "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$headers .= "X-Priority: 1" . "\r\n";

if(mail('', 'hello', 'world', $headers)){
echo "Status: OK";
echo "Status: False";

When I run I receive the following message: "Status: False", Of course I don´t configure the mail server.

For this I use this steps:

1°: Change my hostname to ""
2°: Check if the linux command "hostname" return "" (Yes it returns)
3°: Install postfix "sudo apt-get install postfix", select internet, and insert "" inside system mail.

Great! Let´s test my php file and now I receive the message: "Status: OK", Great! Now lets wait for my email.....(5 minutes).....(1 hour)......(1 day)...... NOTHING COMES TO MY HOTMAIL.

What I´m doing wrong??

1 Answer

Hi @sdanz,

It seems like there could be a configuration problem with your linux server's mail system. Have you looked in the logs (/var/log), specifically the mail log, to see if there are any error messages there? Which mail transfer system have you been using?

If you haven't setup a mail system yet, have a look through this tutorial:

Please let us know if you get things sorted!

Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email. In this tutorial, we will install and configure Postfix so that it can be used to send emails by local applications only.
Have another answer? Share your knowledge.