PHP mail()从命令行工作,但不是apache [英] PHP mail() works from command line but not apache
问题描述
我试图找出为什么通过Web浏览器(即apache)调用PHP时,邮件功能失败,但是我可以使用
I'm trying to figure out why the mail function in PHP fails when called via web browser (i.e. apache), but I can run the same script from the command line using
php -f mailtest.php
php -f mailtest.php
这是我客户端的Fedora服务器之一,所以我完全不了解它,但是如果需要更改任何内容,我确实有root权限。
This is one of my client's Fedora servers, so I don't grok it completely, but I do have root access should I need to change anything.
从php.ini:
sendmail_path = / usr / sbin / sendmail -t -i
sendmail_path = /usr/sbin/sendmail -t -i
不确定如果这样可以重要,但是/ usr / sbin / sendmail是/ etc / alternatives / mta的符号链接,它是一个回到/usr/sbin/sendmail.sendmail的符号链接。 FWIW apache用户有权运行sendmail(直接从命令行测试的sendmail)。
Not sure if this could matter, but /usr/sbin/sendmail is a symlink to /etc/alternatives/mta, which is a symlink back to /usr/sbin/sendmail.sendmail. FWIW the apache user does have permission to run sendmail (tested sendmail directly from the command line).
OS: Fedora Core 7 Linux (kernel 2.6.23.17)
Apache: 2.2.8
PHP: 5.2.6
Any help here will be greatly appreciated!
推荐答案
我发现问题。 SELinux阻止apache使用sendmail。要诊断,我使用
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
然后实际解决问题:
$ restorecon /usr/sbin/sendmail
$ setsebool -P httpd_can_sendmail 1
了解更多信息 here 。
这篇关于PHP mail()从命令行工作,但不是apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!