Bohdan Vorona
Bohdan Vorona

Reputation: 725

PHP function mail() doesn't work on AWS EC2 server

Recently I installed an AWS EC2 virtual server based on Ubuntu 14.04. But I have the next problem: the PHP function mail() doesn't work.


  1. I removed sendmail.
  2. I installed sendmail:

    sudo apt-get install sendmail

  3. I check its working:

    ps -aux | grep sendmail

  4. I changed php.ini:

    sendmail_path = /usr/sbin/sendmail

  5. I run:

    sudo sendmailconfig

Selected Yes for all categories.

  1. Restarted the service:

    service sendmail restart

  2. Added my hostname to /etc/hosts:

    127.0.0.1 localhost.localdomain localhost myhostname

  3. I tried to test sending:

    echo -e "To: [email protected]\nSubject: Test\nTest\n" | sendmail -bm -t -v

enter image description here

All emails stored in /var/mail/ubuntu.


Shall I do any additional things?

Upvotes: 0

Views: 4905

Answers (2)

Lance Cleveland
Lance Cleveland

Reputation: 3204

Ubuntu 16.04 LTS, the "default" Ubuntu image for Amazon EC2 as of September 2016, will need the Postfix MTA installed and configured for PHP to send mail.

sudo apt-get update
sudo apt install mailutils

Keep "internet site" selected and enter your proper host name.

Then use your favorite editor, vim or nano or whatever, and fix up the main.cf file to process traffic from local network interfaces (loopback) only and to set the domain to your proper host domain name.

sudo systemctl restart postfix

See this for details: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04

That is all the magic needed to get outbound email working on my Ubuntu 16.04 running a WordPress app.

Good luck.

Upvotes: 1

Davinder Kumar
Davinder Kumar

Reputation: 662

Mail functions does not work in cloud based servers like aws,azure. I have already faced this issue and resolved with php mailer library so i suggest you to use this.

Upvotes: 1

Related Questions