Web lists-archives.com

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




# cat /etc/redhat-release
CentOS release 6.5 (Final)


# yum list|grep sendmail
sendmail.x86_64
           8.14.4-9.el6                   @base
sendmail-cf.noarch                       8.14.4-9.el6                   @base
sendmail-devel.i686                      8.14.4-9.el6                   base
sendmail-devel.x86_64                    8.14.4-9.el6                   base


]# yum list|grep sendmail
sendmail.x86_64                          8.14.4-9.el6                   @base
sendmail-cf.noarch                       8.14.4-9.el6                   @base
sendmail-devel.i686                      8.14.4-9.el6                   base
sendmail-devel.x86_64                    8.14.4-9.el6                   base
sendmail-doc.noarch                      8.14.4-9.el6                   base
sendmail-milter.i686                     8.14.4-9.el6                   base
sendmail-milter.x86_64                   8.14.4-9.el6                   base


# rpm -ql sendmail
/etc/NetworkManager/dispatcher.d/10-sendmail
/etc/mail
/etc/mail/Makefile
/etc/mail/access
/etc/mail/access.db
/etc/mail/aliasesdb-stamp
/etc/mail/domaintable
/etc/mail/domaintable.db
/etc/mail/helpfile
/etc/mail/local-host-names
/etc/mail/mailertable
/etc/mail/mailertable.db
/etc/mail/make
/etc/mail/sendmail. cf
/etc/mail/sendmail. mc
/etc/mail/submit. cf
/etc/mail/submit. mc
/etc/mail/trusted-users
/etc/mail/virtusertable
/etc/mail/virtusertable.db
/etc/pam.d/smtp.sendmail
/etc/rc.d/init.d/sendmail
/etc/sasl2/Sendmail.conf
/etc/smrsh
/etc/sysconfig/sendmail
/usr/bin/hoststat
/usr/bin/mailq.sendmail
/usr/bin/makemap
/usr/bin/newaliases.sendmail
/usr/bin/purgestat
/usr/bin/rmail.sendmail
/usr/lib/sendmail.sendmail
/usr/sbin/mailstats
/usr/sbin/makemap
/usr/sbin/praliases
/usr/sbin/sendmail.sendmail
/usr/sbin/smrsh
/usr/share/doc/sendmail-8.14.4
/usr/share/doc/sendmail-8.14.4/FAQ
/usr/share/doc/sendmail-8.14.4/KNOWNBUGS
/usr/share/doc/sendmail-8.14.4/LICENSE
/usr/share/doc/sendmail-8.14.4/README
/usr/share/doc/sendmail-8.14.4/RELEASE_NOTES.gz
/usr/share/man/man1/mailq.sendmail.1.gz
/usr/share/man/man1/newaliases.sendmail.1.gz
/usr/share/man/man5/aliases.sendmail.5.gz
/usr/share/man/man8/mailstats.8.gz
/usr/share/man/man8/makemap.8.gz
/usr/share/man/man8/praliases.8.gz
/usr/share/man/man8/rmail.8.gz
/usr/share/man/man8/sendmail.sendmail.8.gz
/usr/share/man/man8/smrsh.8.gz
/var/log/mail
/var/log/mail/statistics
/var/spool/clientmqueue
/var/spool/mqueue

# which sendmail
/usr/sbin/sendmail


# ls -al /usr/sbin/sendmail
lrwxrwxrwx 1 root root 27 Aug 22 17:23 /usr/sbin/sendmail ->
/usr/sbin/sendmail.sendmail


# ls -al /usr/sbin/sendmail.sendmail
-rwxr-xr-x 1 root smmsp 833544 Jul 24 03:48 /usr/sbin/sendmail.sendmail


and apache config:

#
User www
Group www


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.

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