Test mail with PHP mail() ending up in 'dead.letter' (LAMP on Ubuntu 14.04 Droplet)


I am new to Digital Ocean and Linux admin in general. Trying to migrate my site from shared hosting to Digital Ocean.

Just created an “One Click LAMP on 14.04” droplet for my old Codeigniter 2 site. Have transferred the files and pointed the domain to given IP. Seems everything is fine for now.

I have a page with contact from, which uses a PHP mail() function.

Recently I found out that its not working on DO server (was working fine on my shared hosting).

When I submit the form, instead of mail sent feedback message, my form reloads.

Tried to check that in developer console and found out that I am not getting any AJAX response

Exact Message:

TypeError: response is null

After some googling, I figured out that PHP mail() is compiled to use sendmail by default and was not installed on my droplet instance.

Followed the instruections from here:

Did this:

$ sudo apt-get install sendmail mailutils sendmail-bin

$ sudo nano /etc/hosts

-> <my.domain> <my.domain>  {just replaced the droplet name with my domain}
-> localhost localhost.localdomain <my.domain>

$ sudo sendmailconfig

-> answered 'y" to everything

I have php script to test this with sender, receiver, message. Whenever I try sending test mail, I get message

/home/<uername>/dead.letter... saved message in /home/<username>/dead.letter

Can’t figure out what’s going on.

Need some clues and suggestions.


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I am able to send mail as current user for now. I tried this steps:

(1) Checked mail as current user using ‘mail’

$ mail


(2) Then turned off the machine

$sudo poweroff

(3) Then powered on the droplet from web interface

After that I am able to send mail

$ php mailtest.php  //this is my script with sender, receiver etc.

However, the $sender field I set was ignored. When I received the mail. Its was sent as


I am not really sure why I have to use ‘mail’ to make it work. After that I have “mbox” file in my home folder.

So far I am able to make it work. However my web contact form is still not working.

I am suspecting the permission issue.

I guess when mail is triggered from web form, sender is set as ‘www-data’, which doesn’t have proper permission to use sendmail.

So my question now is how to allow ‘www-data’ to use sendmail. I think once i figure that out, it should be fine.

Just found this and tried to follow what was suggested here but no luck

Any suggestion?