PHP sendmail runs on Ubuntu command line but not from php file

I installed sendmail with PHP and apache on Ubuntu. When I try to execute the following command

php -r "mail(' test@gmail.com ', 'test', 'test')"' 

he successfully sends an email.

However, by running the file "test_send_mail.php" with

 <?php mail(' test@gmail.com ', 'test', 'test') ?> 

Don't send an email.

A failed .php file attempt generates a log entry:

 `Jul 5 21:24:47 www sendmail[25603]: p661OlL7025603: from=www-data, size=106, class=0, 

nrcpts = 0, msgid = < 201107060124.p661OlL7025603@www.server.com >, relay = www-data @localhost

A successful command line attempt generates a log entry:

  Jul 5 21:22:40 www sm-mta[25533]: p661MevV025533: from=< root@www.server.com >, size=352, class=0, nrcpts=1, msgid=< 201107060122.p661Mecm025532@www.server.com >, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] 

Does anyone know what could happen? Thanks for the help!

+6
source share
3 answers

PHP Has separate ini files depending on the environment:

  • Kli /php.ini
  • Cgi / php.ini
  • php.ini

Make sure that you have made all the necessary changes in all files, cgi is usually used for Nginx and Lighttpd, but in order to be sure, copy the settings in all 3.

You can also run the phpinfo(); function phpinfo(); to see which settings are actually used.

it could also be a direct fix: PHP email problem with www data

+1
source

Perhaps your system prevents sending apache mail. See a similar question:

fooobar.com/questions/595719 / ...

+1
source

Your failed attempt sends email as a web server user. You probably don't want to do this. The key must pass more mail() parameters in order to override these default values, as it passes the email to your injector.

See the comments on the manual page for mail() , and there will be a lot of help for this.

0
source

Source: https://habr.com/ru/post/892086/


All Articles