簡體   English   中英

通過網絡服務器運行時無法發送郵件,但能夠從命令行發送相同的PHP腳本

[英]Not able to send mail when running through webserver but able to send from command line with same php script

我面臨一個奇怪的問題:我在項目中有一個名為mail.php的文件。 當我從shell運行命令時:

php mail.php

它在幾秒鍾內發送郵件,但在運行相同的文件時:

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

使用此代碼沒有郵件出去:

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

有人能幫助我嗎?

可能是SELinux已啟用,並且根據SELinux默認配置,不允許通過apache / web服務器發送郵件。

要檢查SELinux是否已啟用且配置為停止發送電子郵件,請運行以下命令:

getsebool -a | grep mail

樣本輸出

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

現在,為了配置SELinux以允許apache發送電子郵件,運行以下命令:

setsebool -P httpd_can_sendmail on

檢查這個答案,它解決了我的問題: 無法通過網絡服務器運行時發送郵件,但能夠從命令行發送相同的PHP腳本

可能的方法:

在php.ini中替換

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

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

然后重啟Apache。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM