PHP mail() function enable

August 22, 2012 162.5k views
Hi DigitalOcean team, first of all, congrats for everything ! That an awesome service ! Next, I would know how to enable the mail() fonction. By default I think it's disabled because I received an error with wordpress trying to retreive a lost password. Le message n’a pas pu être envoyé. Raison possible : votre hébergeur peut avoir désactivé la fonction mail()… The message can't been sent. Possible reason : your host has maybe deactivated mail() function... Thank you
17 Answers
Indeed, the steps I took were

1) If sendmail isn't installed, install it: apt-get install sendmail
2) Configure hosts file correctly: nano /etc/hosts
And make sure the line looks like this: localhost localhost.localdomain yourhostnamehere
3) Run the sendmail config and answer 'Y' to everything: sendmailconfig

I restarted apache for good measure: service apache2 restart

After that my mail was sending instantly.
  • @collinpatrickhenderson Thanks for your post, I followed it sort of..
    Note: On Digital Ocean Ubuntu 14.04 LAMP image.

    1) ran $ sendmail
    This told me sendmail could be found in the following packages:

    • exim4-daemon-heavy
    • exim4-daemon-light
    • lsb-invalid-mta
    • postfix
    • citadel-mta
    • courier-mta
    • dma
    • esmtp-run
    • masqmail
    • msmtp-mta
    • nullmailer
    • opensmtpd
    • qmail-run
    • sendmail-bin
    • ssmtp
    • xmail

    I decided to install the sendmail-bin. I believe this is all that is needed. For sending mail from form etc.

    2) $ sudo apt-get install sendmail-bin

    Then checked hosts file.
    3) $ nano /etc/hosts
    Looked like: myhostname myhostname localhost
    4) control+x to quit nano

    Then ran:
    5) $ sudo sendmailconfig

    Accepted Y to all choices. I think there was three or four..Once finished..

    Tested again with:
    6) $ sendmail
    Test message

    It worked nicely. Only thing now is I wonder how much more should be configured for security and performance, I did see a lot in that configuration.. Someone should do a tutorial on sendmail configuration???

I was having the same problem - sendmail WAY too slow. Found fix for it here:
Thank you api2 i've tryed that, but it's not working has is, so for others, here is the hole walkthrough

log has root or use sudo

apt-get install php-pear
pear install mail
pear install Net_SMTP
pear install Auth_SASL
pear install mail_mime

apt-get install postfix
you should get a install dialog ensure that the Internet site is selected and the Mail server name is localhost

vi /etc/php5/apache2/php.ini set sendmail path to /usr/sbin/sendmail -t -i

Reboot apache gracefully
apachectl graceful

Now you're all done !

  • Works great. but have one issue. mail is received in spam folder, and send from address is www-data@dropletName
    how do i solve that ?

Why don't you use this way: . This is excellent tutorial and I have never got problem with it. I am using Gmail as SMTP server and everything is both super fast and reliable.
Read through this tutorial to learn how to use Gmail or Yahoo with PHP mail() function.
Hi Jonathan,

Sorry I don't speak French, any chance you could convert that to english?

Also check the functionality of your basic mail delivery from the command line:

# sendmail
Body of Test Message

If that mail gets delivered then we know its not a systems problem but an issue with how it's interacting with Wordpress/PHP.

Hi Raiyu,

Here is the error I received on my terminal when I try sendmail
-bash: sendmail: command not found

For the french message, it's already translated right after the french part,

The message can't been sent. Possible reason : your host has maybe deactivated mail() function

Like i've asked, I would know if there's possible to explain me how to install a mail service, don't need to be "real" email, but just to enable the system to send me some information via e-mail when needed.

Thank you !
Hey Jonathan,

It sounds like your server is missing an SMTP service to deliver email. You can install sendmail which should enable these features for you.

yum install sendmail (CentOS)
apt-get install sendmail (Ubuntu)

Verify that your mail server is now online by sshing into your server and running:

telnet localhost 25

If that works mail should be enabled on your server.
if you receive : postdrop: warning: unable to look up public/pickup: No such file or directory.

That mean that sendmail was previously installed and that messing things up. So do the following :

mkfifo /var/spool/postfix/public/pickup
ps aux | grep sendmail
service postfix restart
Have you tried WP SMTP plugin? It worked for me.
I'm about to quit DigitalOcean. The instructions on Postfix don't work. Sendmail takes too long to process a simple form. And I'm tired of trying everything I find to make the stupid php mail( ) function work.
For outbound email you do not need to install an MTA like postfix, just point it your sendmail binary and that's enough to send mail out.

That's because all of the heavy lifting is done on the remote side where your emails are being delivered to.
Hey everyone,

I've followed this from not using postfix to setting up sendmail. I somehow didn't have a hostname in my sendmail which added my server to the spamhaus project... I added that and now I'm ok there, all clear and indeed my wordpress' are sending emails! (using this and adding to your and

Unfortunately they're getting caught up in gmail's spam filters. I found SPF fails in the email headers so I've added SPF records to my domains to allow my server IP and Google's MX stuff too and they now pass ok!

v=spf1 a mx ip4:{my server ip} ip4:{xxx.xx.0.1/16 - dreamhost's mail DNS stuff} ~all

Now they're still getting caught in my spam filters.


I get:

Received: by with SMTP id cy5csp107306qeb;
Wed, 24 Jul 2013 18:37:41 -0700 (PDT)
X-Received: by with SMTP id tt1mr729802vdc.2.1374716260930;
Wed, 24 Jul 2013 18:37:40 -0700 (PDT)
Received: from ( [])
by with ESMTPS id sj10si11347043vdc.66.2013.
(version=TLSv1 cipher=DES-CBC3-SHA bits=168/168);
Wed, 24 Jul 2013 18:37:40 -0700 (PDT)
Received-SPF: pass ( domain of designates as permitted sender) client-ip=;
spf=pass ( domain of designates as permitted sender)
Received: from ( [])
by (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id r6P1bdRU001624
for ; Thu, 25 Jul 2013 01:37:39 GMT
Received: (from www-data@localhost)
by (8.14.4/8.14.4/Submit) id r6P1bdeU001623;
Thu, 25 Jul 2013 01:37:39 GMT
Subject: test
X-PHP-Originating-Script: 33:class-phpmailer.php
Date: Thu, 25 Jul 2013 01:37:39 +0000
From: matt
Message-ID: <>
X-Priority: 3
X-Mailer: PHPMailer 5.2.1 (
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UTF-8"

From: matt
Subject: test

Message Body:

This mail is sent via contact form on Art Work


Any ideas?? I've tested multiple different wordpress platforms from my server and same business :(

Could it be I need a fully qualified hostname? Essentially I would like a variety of domains to sendmail from my single server. Not sure where else to explore.

Found this too:

If you are sending from a fully qualified domain, add it to the local-host-names file. In Ubuntu, it would be /etc/mail/local-host-names. Make sure it reads something like this:

[server name]

Now in the /etc/hosts, make sure it reads the following. [] [server name] localhost


sudo /etc/init.d/sendmail restart


But once again, I need multiple domains sending from this singe server. Any advice would be greatly appreciated!

Then this

If you dont use your .mc files then you can add the following definition to your and
Hey everyone, I contacted support and they pointed me to which revealed my server has been blacklisted again (probby when hostname testing) and I need to setup DKIM.

In retrospect, I think using a third party, already established mail provider throgh SMPT in Wordpress is easiest. I found a solid tutorial:
By using a Wordpress SMTP plugin you get to take advantage of a dedicated mail server, rather than relying solely on your droplet. On my tests I have found that using SMTP plugin with a Google and GoDaddy mail servers gets the contact form into my inbox faster than it does with setting up a mail server. It also simplifies your sever configuration.

After changing my hosts file my email sends from this address:


Any ideas?
@sloan.eric: You can change that by setting the "From" header: (additional_headers).

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

Have another answer? Share your knowledge.