Re: php mail function not work from apache,but work well from command line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The issue is that when you do this through the CLI you are running
as a normal user. When you call this script/page via a browser it's
running as the httpd server. On my centos-6.7, php-5.3.3 (you should
really upgrade) system the latter approach is being blocked by
selinux.

Did you run the:

  sestatus -b | grep sendmail

command as suggested earlier? When I do I get:

  httpd_can_sendmail off

on my centos system, with selinux "enforcing". When I disable
selinux, sending via the browser call to the script works.

I.e., there are no bugs here -- just a system configuration issue.

If you aren't seeing anything on these (both success and failure) in
your maillog I suspect that you aren't looking at the correct log.
You need to make certain that you are looking at, and taking actions
on, the correct environment.

[please **DO NOT** include my email address in your reply. i'm on
the list and get the messages just fine that way.]


------------ Original Message ------------
> Date: Sunday, August 23, 2015 10:35:35 +0800
> From: Xinhao Zheng <xinhaozheng@xxxxxxxxx>
>
> yes.reboot with no luck.
> 
> one more thing,i run apache as reverse proxy,the frontend is
> nginx.but i think this has nothing to do with mail function.
> 
> there is no log in apache error log,neither in /var/log/maillog.
> so any other idea.
> i googled a lot, tweak sendmail config, check the user perm ....
> 
> somebody said this may be a bug in php5.3.28?
> 
> 
> 
> 
> On Sun, Aug 23, 2015 at 10:19 AM, Xinhao Zheng
> <xinhaozheng@xxxxxxxxx> wrote:
>> # cat /etc/redhat-release
>> CentOS release 6.5 (Final)
>> 
>> 
  < snip >
>> 
>> i tried chmod 777 to sendmail with no lucky shot.  it seems
>> apache is not allow to send mail.
>> 
>> 
>> On Sun, Aug 23, 2015 at 9:56 AM, Aziz Saleh <azizsaleh@xxxxxxxxx>
>> wrote:
>>> 
>>> 
>>> 
>>> On Sat, Aug 22, 2015 at 9:53 PM, Xinhao Zheng
>>> <xinhaozheng@xxxxxxxxx> wrote:
>>>> 
>>>> i tried that.SElinux is off.
>>>> thanks!
>>>> 
>>>> On Sun, Aug 23, 2015 at 9:45 AM, Aziz Saleh
>>>> <azizsaleh@xxxxxxxxx> wrote:
>>>>> 
>>>>> 
>>>>> 
>>>>> On Sat, Aug 22, 2015 at 9:31 PM, Xinhao Zheng
>>>>> <xinhaozheng@xxxxxxxxx> wrote:
>>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>>   Thanks for help.
>>>>>> 
>>>>>> i am sure they share the same config file.
>>>>>> /usr/local/php5.3.28/bin/php --ini   shows
>>>>>> /usr/local/php5.3.28/etc/php.ini and phpinfo page show same
>>>>>> config file
>>>>>> 
>>>>>> yes,i run same file.
>>>>>> 
>>>>>> command line => /usr/local/php5.3.28/bin/php
>>>>>> /path/to/webroot/test_mail.php web browser =>
>>>>>> http://IP/test_mail.php
>>>>>> 
>>>>>> source code of test_mail.php
>>>>>> 
>>>>>> <?php
>>>>>> define('DEBUG_MODE',1);
>>>>>> if (defined('DEBUG_MODE') ) {
>>>>>>     error_reporting(E_ALL);
>>>>>>     ini_set('display_errors',TRUE);
>>>>>>     ini_set('error_log','/tmp/log_php');
>>>>>>     ini_set('log_errors',TRUE);
>>>>>> }
>>>>>> 
>>>>>> $message = "Line 1\nLine 2\nLine 3" . date('Y-m-d') . ' unix
>>>>>> timestamp ' . time();
>>>>>> $message = wordwrap($message, 70);
>>>>>> $ok = mail('mail1@xxxxxxxxx', 'My Subject' . date('Y-m-d') .
>>>>>> ' meeting', $message);
>>>>>> var_dump($ok);
>>>>>> $ok = mail('mail2@xxxxxxxxx', 'My Subject' . date('Y-m-d') .
>>>>>> ' meeting', $message);
>>>>>> var_dump($ok);
>>>>>> 
>>>>>> ?>
>>>>>> 
>>>>>> On Sun, Aug 23, 2015 at 12:19 AM, Richard <
>>>>>> replies-lists-e7x6-php@xxxxxxxxxxxxxxxxxxxxx> wrote:
>>>>>> 
>>>>>> > 
>>>>>> > 
>>>>>> > > Date: Saturday, August 22, 2015 09:51:45 -0400
>>>>>> > > From: Aziz Saleh <azizsaleh@xxxxxxxxx>
>>>>>> > > 
>>>>>> > > On Sat, Aug 22, 2015 at 5:50 AM, Xinhao Zheng
>>>>>> > > <xinhaozheng@xxxxxxxxx> wrote:
>>>>>> > > 
>>>>>> > >> Hello,
>>>>>> > >> 
>>>>>> > >>     i got a prolem.php mail() function can not send
>>>>>> > >>     email from http request(apache),but it work well if
>>>>>> > >>     i call it from command line.
>>>>>> > >> 
>>>>>> > >> /usr/local/php5.3.28/bin/php test_mail.php
>>>>>> > >> => ok http://ip/test_mail.php                  => failed.
>>>>>> > >> 
>>>>>> > >> i check both apache  error log and /var/log/maillog,but
>>>>>> > >> nothing get there. i am running php5.3.28 over apache as
>>>>>> > >> module. with phpinfo and this command,
>>>>>> > >> /usr/local/php5.3.28/bin/php --ini , i am sure they use
>>>>>> > >> same php config file.i also tried to turn off the
>>>>>> > >> iptable,but no lucky shot.
>>>>>> > >> 
>>>>>> > >> 
>>>>>> > >> 
>>>>>> > > Use phpinfo() to confirm they are using the same configs.
>>>>>> > 
>>>>>> > Are you accessing the same "test_mail.php" page/code in
>>>>>> > both cases? If so, I really wouldn't expect it to work as
>>>>>> > the environments are totally different.
>>>>>> > 
>>>>>> > Show your code.
>>>>>> > 
>>>>>> > By the way, if you aren't generating a message (nothing in
>>>>>> > /var/log/maillog) then mucking with iptables will have no
>>>>>> > effect.
>>>>>> > 
>>>>>> > 
>>>>>> > --
>>>>>> > PHP General Mailing List (http://www.php.net/)
>>>>>> > To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>> > 
>>>>>> > 
>>>>> 
>>>>> 
>>>>> Try running:
>>>>> 
>>>>> sestatus -b | grep sendmail
>>>>> 
>>>>> from command prompt, you are probably using SELinux and have
>>>>> httpd_can_sendmail set to off, in which case you can send mail
>>>>> via CLI but not Apache.
>>>> 
>>>> 
>>> 
>>> I have ran into issues in the past where if I disabled SELinux,
>>> I had to restart the server for it to take effect, not sure if
>>> it is the same issue on your end, but wouldn't hurt to try if
>>> you haven't.

------------ End Original Message ------------



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux