PHP mail()从命令行工作,但不是apache [英] PHP mail() works from command line but not apache

查看:164
本文介绍了PHP mail()从命令行工作,但不是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 mailtest.php

php -f mailtest.php

这是我客户的Fedora服务器之一,我不会完全,但我有根访问,我需要改变任何东西。

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

任何帮助将非常感谢!

推荐答案

我发现了问题。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆