matt matt - 1 year ago 103
Apache Configuration Question

PHP mail() works from command line but not 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

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.

from php.ini:

sendmail_path = /usr/sbin/sendmail -t -i

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
Apache: 2.2.8
PHP: 5.2.6

Any help here will be greatly appreciated!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download