Ubuntu 14.04 mail() dont send email

June 14, 2016 2.3k 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: ”. “help@mysite.com”. “\r\n”;
$headers .= “X-Mailer: PHP/” . phpversion();
$headers .= “X-Priority: 1” . “\r\n”;

if(mail(’mymail@hotmail.com’, ‘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 “mymail.mysite.com”
2°: Check if the linux command “hostname” return “mymail.mysite.com” (Yes it returns)
3°: Install postfix “sudo apt-get install postfix”, select internet, and insert “mymail.mysite.com” 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: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-14-04

Please let us know if you get things sorted!

by finid
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.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!