Web lists-archives.com

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




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.