My problem is that php script which has to send mail doesn't send it if I run it in browser, but works in cli. This doesn't help PHP's mail() function working in CLI but not in Apache
In both /etc/php/7.0/fpm and /etc/php/7.0/cli same mail settings:
SMTP = localhost
smtp_port = 25
sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t"
mail.add_x_header = On
mail.log = /var/log/maillog
If I type in terminal
php -r mail("my_mail@gmail.com", "Test", "test");
it works, also it works if I type
sudo -u www-data php -r mail("my_mail@gmail.com", "Test", "test");
However, if I try to send mail from php interactive mode php -a
and then simply type there mail("my_mail@gmail.com", "Test", "test");
I get /etc/msmtprc permission denied
. I tried to chmod 666 /etc/msmtprc
(however ls -al
shows -rw------- 1 www-data www-data 267 Apr 4 11:10 /etc/msmtprc
, so I think no need in allowing access) I get error like msmtp: /etc/msmtprc: contains secrets and therefore must be owned by you
file msmtprc
is chmodded this way chmod 600 msmtprc
, according to many tutorials.