PHP mail() 从命令行工作,但不是 apache [英] PHP mail() works from command line but not apache
问题描述
我试图弄清楚为什么 PHP 中的邮件功能在通过 Web 浏览器(即 apache)调用时失败,但我可以使用
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 邮件测试.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:
from 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
在此处阅读更多相关信息.
这篇关于PHP mail() 从命令行工作,但不是 apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!