PHP mail() works from command line but not apache

五迷三道 提交于 2019-11-27 15:20:10
matt

I found the problem. SELinux was preventing apache from being able to use sendmail. To diagnose, I used

$ sestatus -b | grep sendmail  
httpd_can_sendmail                   off

Then to actually fix the problem:

$ restorecon /usr/sbin/sendmail
$ setsebool -P httpd_can_sendmail 1

Read more about it here.

Is it a user permissions error? Your account and the one used to execute PHP scripts may have different privileges.

Anything in apache's error_log? Is PHP being run as an apache module or a CGI binary?

EDIT: Hmmm... nothing in the error log. What does the call to mail(...) return? Anything interesting in the mail log? This will vary depending on the MTA, often /var/log/maillog

EDIT 2: Is safe_mode turned on and are you using the mail() function's additional_parameters ?

This is my first answer here on StackOverflow! :o

So I had the same issue than you, matt! I use OpenSuse. I figured out that postfix check resulted with

postfix/postfix-script: warning: not owned by group maildrop: /usr/sbin/postqueue
postfix/postfix-script: warning: not owned by group maildrop: /usr/sbin/postdrop
postfix/postfix-script: warning: not set-gid or not owner+group+world executable: /usr/sbin/postqueue
postfix/postfix-script: warning: not set-gid or not owner+group+world executable: /usr/sbin/postdrop

so I ran the next commands:

# my postfix user is postfix and postfix group is maildrop
sudo chown 'postfix:maildrop' /usr/sbin/post{drop,queue}
sudo chmod g+s /usr/sbin/post{queue,drop}

and then, I tried to simple PHP script from my browser to test if everything works fine: (assuming you want to mail abc@gmail.com)

<?php
$ret = mail('abc@gmail.com', 'subject', 'message');
if ($ret === true)
  echo 'Success'.PHP_EOL;
else
  echo 'Error'.PHP_EOL;

and that's fine! I hope you will fix the issue with this method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!