Page 1 of 1

mail.php work from terminal but not from web browser

PostPosted: 26. May 2021 01:09
by cefer
If in a terminal run /opt/lamp/bin/php mail.php the result is OK
but from web browser: localhost/devel/newsite/mail.php the result is FAIL
What happen here?

<?php
$to="to some mailbox in the world";
$subject="Test ONE";
$message="Testing testing";
$from = "mipc@yo.com";
$headers = "From: ".$from;

if (mail($to,$subject,$message,$headers)) {
echo "OK";
} else {
echo "FAIL";
}
?>

Re: mail.php work from terminal but not from web browser

PostPosted: 26. May 2021 02:58
by cefer
Searching in internet and testing later, I see what in php.ini the senmail_path need "env -i" so the line now is: sendmail_path = "env -i /usr/sbin/sendmail -t -i"
Now the result is OK, but no mail is out (from terminal yes, the mail out to the inbox)

Re: mail.php work from terminal but not from web browser

PostPosted: 26. May 2021 10:25
by Nobbie
In terminal your UserId from Linux is executing the process, in Apache a system user (in Xampp it is "daemon") is running the process. Probably they are not granted to the same rights for sending and receiving mails.

You might change the UserId for Apache Execution in httpd.conf (see value of USER in httpd.conf).