Reputation: 725
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.
I installed sendmail:
sudo apt-get install sendmail
I check its working:
ps -aux | grep sendmail
I changed php.ini:
sendmail_path = /usr/sbin/sendmail
I run:
sudo sendmailconfig
Selected Yes for all categories.
Restarted the service:
service sendmail restart
Added my hostname to /etc/hosts:
127.0.0.1 localhost.localdomain localhost myhostname
I tried to test sending:
echo -e "To: [email protected]\nSubject: Test\nTest\n" | sendmail -bm -t -v
All emails stored in /var/mail/ubuntu.
Shall I do any additional things?
Upvotes: 0
Views: 4905
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
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