Question

PHP mail() function enable

Posted August 22, 2012 338.4k 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

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.

×
Submit an Answer
19 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: 127.0.0.1 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 myemail@yahoo.com
    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:
    127.0.1.1 myhostname myhostname
    127.0.0.1 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 myemail@yahoo.com
    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???

  • The sendmail package doesn’t work with ubuntu 16.04.
    It has some malware issue.

    Even though i tried to remove it completely from ubuntu. it still uses the CPU (DISK I/O) almost upto 99%.

I was having the same problem - sendmail WAY too slow. Found fix for it here: http://www.flogiston.net/blog/2009/05/11/sendmail-painfully-slow-on-ubuntu/
Why don't you use this way: https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function . 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.
by Jesin A
Read through this tutorial to learn how to use Gmail or Yahoo with PHP mail() function.
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 !

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 user@domain.com
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.

Thanks
Hi Raiyu,

Here is the error I received on my terminal when I try sendmail info@jonathanlafleur.ca
-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
kill
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.
Previous 1 2 Next