I can’t send mail while working through the web server, but can send from the command line with the same PHP script

I had a strange problem: there is a mail.php file in the project. When I run the command from the shell:

php mail.php 

it sends mail in seconds, but when you run the same file as:

 https://www.domain.com/mail.php 

No mail comes out using this code:

 <?php echo "Sending mail now...."; mail(" mr.atanu.dey.83@gmail.com ", "PHP Test mail", "Hope this works! "); ?> 

Can someone help me?

+4
source share
2 answers

It is possible that SELinux is turned on and, by default, SELinux does not allow sending mail using apache / web server.

To verify that SELinux is enabled and configured to stop sending emails, run the following command:

 getsebool -a | grep mail 

output sampling

 allow_postfix_local_write_mail_spool --> on httpd_can_sendmail --> off logging_syslogd_can_sendmail --> off 

Now, to configure SELinux to allow apache to send email, run the following command:

 setsebool -P httpd_can_sendmail on 

Check this answer, it will solve my problem: Unable to send mail while working through the web server, but is able to send from the command line with the same php script

+1
source

Possible Solution:

In php.ini replace

sendmail_path = /usr/sbin/sendmail -t -i

with

sendmail_path = /usr/sbin/sendmail.postfix -t -i

Then restart Apache.

0
source

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


All Articles