I'm facing a weird problem: I have a file called mail.php in the project. When I run the command from shell:
我面临一个奇怪的问题:我在项目中有一个名为mail.php的文件。当我从shell运行命令时:
php mail.php
it sends mail in seconds, but when running the same file as:
它在几秒钟内发送邮件,但在运行相同的文件时:
https://www.domain.com/mail.php
No mail is going out, using this code:
使用此代码没有邮件出去:
<?php
echo "Sending mail now....";
mail("mr.atanu.dey.83@gmail.com", "PHP Test mail", "Hope this works! ");
?>
Can somebody help me?
有人能帮助我吗?
2 个解决方案
#1
1
It may be the case that SELinux is enabled and according to SELinux default configuration the mail sending by apache/web server is not allowed.
可能是SELinux已启用,并且根据SELinux默认配置,不允许通过apache / web服务器发送邮件。
To check whether SELinux is enabled and its configured to stop sending email run the below command:
要检查SELinux是否已启用且配置为停止发送电子邮件,请运行以下命令:
getsebool -a | grep mail
sample output
allow_postfix_local_write_mail_spool --> on
httpd_can_sendmail --> off
logging_syslogd_can_sendmail --> off
Now, in order to configured SELinux to allow apache to send email run the below command:
现在,为了配置SELinux以允许apache发送电子邮件,运行以下命令:
setsebool -P httpd_can_sendmail on
Check this answer, it resolve my issue: Not able to send mail when running through webserver but able to send from command line with same php script
检查这个答案,它解决了我的问题:无法通过网络服务器运行时发送邮件,但能够从命令行发送相同的PHP脚本
#2
0
Possible solution:
In php.ini replace
在php.ini中替换
sendmail_path = /usr/sbin/sendmail -t -i
sendmail_path = / usr / sbin / sendmail -t -i
with
sendmail_path = /usr/sbin/sendmail.postfix -t -i
sendmail_path = /usr/sbin/sendmail.postfix -t -i
Then restart Apache.
然后重启Apache。
#1
1
It may be the case that SELinux is enabled and according to SELinux default configuration the mail sending by apache/web server is not allowed.
可能是SELinux已启用,并且根据SELinux默认配置,不允许通过apache / web服务器发送邮件。
To check whether SELinux is enabled and its configured to stop sending email run the below command:
要检查SELinux是否已启用且配置为停止发送电子邮件,请运行以下命令:
getsebool -a | grep mail
sample output
allow_postfix_local_write_mail_spool --> on
httpd_can_sendmail --> off
logging_syslogd_can_sendmail --> off
Now, in order to configured SELinux to allow apache to send email run the below command:
现在,为了配置SELinux以允许apache发送电子邮件,运行以下命令:
setsebool -P httpd_can_sendmail on
Check this answer, it resolve my issue: Not able to send mail when running through webserver but able to send from command line with same php script
检查这个答案,它解决了我的问题:无法通过网络服务器运行时发送邮件,但能够从命令行发送相同的PHP脚本
#2
0
Possible solution:
In php.ini replace
在php.ini中替换
sendmail_path = /usr/sbin/sendmail -t -i
sendmail_path = / usr / sbin / sendmail -t -i
with
sendmail_path = /usr/sbin/sendmail.postfix -t -i
sendmail_path = /usr/sbin/sendmail.postfix -t -i
Then restart Apache.
然后重启Apache。