I have installed postfix and dovecot properly and did all configurations as per this guide: http://www.krizna.com/ubuntu/setup-mail-server-ubuntu-14-04/
But when I try sending mail via terminal like:
sudo php -r "mail('xyz@xyz.com', 'test', 'test');"
It gives me the error
sh: 1: /etc/postfix: Permission denied
I tried doing chmod -R 777
to the /etc/postfix
directory and I still get the same error.
What should I do to get this working? I just want to send mail from my server to other mails like Gmail (i.e. xyz@xyz.com to abc@gmail.com)
I have even configured the mx records and a records in my dns manager.
If I see the Postfix log, I have this:
Feb 2 12:30:33 myhost postfix/pickup[16695]: ED7A120FD3: uid=33 from=<www-data>
Feb 2 12:30:33 myhost postfix/cleanup[4891]: ED7A120FD3: message-id=<20160202173033.ED7A120FD3@xyz.com>
Feb 2 12:30:33 myhost postfix/cleanup[4891]: warning: hash:/etc/postfix/virtual is unavailable. open database /etc/postfix/virtual.db: No such file or directory
Feb 2 12:30:33 myhost postfix/cleanup[4891]: warning: hash:/etc/postfix/virtual lookup error for "xyz@xyz.com"
Feb 2 12:30:33 myhost postfix/cleanup[4891]: warning: ED7A120FD3: virtual_alias_maps map lookup problem for xyz@xyz.com -- message not accepted, try again later
I am using PHP 7 running Apache 2 on Ubuntu 14.04
(Note: Postfix and dovecot seems to be working cause I did telnet as given in the tutorial and got the correct response.)
Got my problem solved. The permission error occured only when accessing Postfix from terminal. It works when accessed from PHP script.
Moreover, I had to modify PHP.ini sendmail path which I set as /etc/postfix before.