Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP sendmail works in Ubuntu command line, but not from a php file

I installed sendmail with PHP and apache on Ubuntu. When I try the following command-line

php -r "mail('[email protected]', 'test', 'test')"'

it successfully sends the email.

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

<?php
mail('[email protected]', 'test', 'test')
?>

doesn't send an email.

The unsuccessful attempt with the .php file generates the log entry:

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

nrcpts=0, msgid=<[email protected]>, relay=www-data@localhost

The successful attempt with the command line generates the log entry:

    Jul  5 21:22:40 www sm-mta[25533]: p661MevV025533: from=<[email protected]>, 
size=352, class=0, nrcpts=1, msgid=<[email protected]>, 
proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]

Does anyone have any idea what might be happening? Thank you for your help!

like image 650
Tim Avatar asked Jul 06 '11 02:07

Tim


1 Answers

PHP Has separate ini files depending on the environment:

  • cli/php.ini
  • cgi/php.ini
  • php.ini

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

Also you can run the phpinfo(); function to see what settings are actually being used.

also this may be the direct fix: PHP mail issue with www-data

like image 143
RobertPitt Avatar answered Sep 17 '22 16:09

RobertPitt