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]

 



Thanks for your reply.

yes.same machine.i do get an access log entry from apache access log
file but no error log.

# sestatus
SELinux status:                 disabled

# /usr/local/php5.3.28/bin/php a.php |grep sendmail
sendmail_from => no value => no value
sendmail_path => /usr/sbin/sendmail -t -i => /usr/sbin/sendmail -t -i
Path to sendmail => /usr/sbin/sendmail -t -i


FROM BROWSER:
sendmail_from    no value    no value
sendmail_path    /usr/sbin/sendmail -t -i    /usr/sbin/sendmail -t -i
Path to sendmail /usr/sbin/sendmail -t -i






On Mon, Aug 24, 2015 at 10:26 AM, Richard
<replies-lists-e7x6-php@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Are you certain you are on/hitting the same machine for your php CLI
> script run and your browser instance? E.g., are you seeing http
> access_log entries for the "test_mail.php" browser attempt on the
> same machine where you are seeing maillog entries for your
> (successful) CLI runs?
>
> I don't have a centos-6.5 machine, so it's possible that more is
> being logged on my 6.7 machine, but with selinux enabled, I'm
> getting 6-7 maillog lines, including:
>
>   Aug 23 13:48:28 xxx sendmail[2138]: t7NDmSYo002138:
>   SYSERR(apache): queueup: cannot create queue file
>   ./qft7NDmSYo002138, euid=48, fd=-1, fp=0x0: Permission denied
>
> for the browser attempts on that script.
>
> What shows in the selinux/config file isn't definitive. Instead of
> showing the contents of that file, issue the command "sestatus"
> (with no options) to see the various status indicators. You should
> see the following:
>
>   SELinux status:
>   SELinuxfs mount:
>   Current mode:
>   Mode from config file:
>
> The values shown for first and third lines are the relevant ones for
> your system's current status.
>
> By the way, what is shown in the phpinfo() output -- for both the
> CLI and browser -- for:
>
>     sendmail_path
>     Path to sendmail
>
>
>> Date: Monday, August 24, 2015 08:54:24 +0800
>> From: Xinhao Zheng <xinhaozheng@xxxxxxxxx>
>>
>> Thanks for your reply.
>>
>>#  sestatus -b | grep sendmail
>> get nothing
>>
>># cat /etc/selinux/config
>>
>># This file controls the state of SELinux on the system.
>># SELINUX= can take one of these three values:
>>#     enforcing - SELinux security policy is enforced.
>>#     permissive - SELinux prints warnings instead of enforcing.
>>#     disabled - No SELinux policy is loaded.
>> SELINUX=disabled
>># SELINUXTYPE= can take one of these two values:
>>#     targeted - Targeted processes are protected,
>>#     mls - Multi Level Security protection.
>> SELINUXTYPE=targeted
>>
>>>>>> If you aren't seeing anything on these (both success and
>>>>>> failure) i
>> if i try to send email from command line,i do get mail log from
>> /var/log/maillog but no if i try to send from browser.
>>
>>
>> On Sun, Aug 23, 2015 at 10:47 PM, Richard wrote:
>>> 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 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.
>>>>>>>>> >
>>>>>>>>
>>>>>>>> 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 ------------
>
> ------------ End Original Message ------------
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
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