首頁  >  文章  >  後端開發  >  為了使用郵箱服務,php7該如何設定sendmail

為了使用郵箱服務,php7該如何設定sendmail

醉折花枝作酒筹
醉折花枝作酒筹轉載
2021-08-10 09:13:272152瀏覽

Sendmail作為一種免費的郵件伺服器軟體,已被廣泛的應用於各種伺服器中,它在穩定性、可移植性、及確保沒有bug等方面具有一定的特色,且可以在網路中搜尋到大量的使用資料。

為了使用郵箱服務,php7該如何設定sendmail

假如嫌自己設定伺服器麻煩,直接使用PHPMailer呼叫第三方郵件伺服器,簡單省事。 git位址如下:

https://github.com/PHPMailer/PHPMailer

1.安裝元件

yum install sendmail mailx

2.修改設定檔/etc/mail.rc

新增下列參數:

set from=acc@163.com  #发送方
set smtp=smtp.163.com
set smtp-auth-user=acc@163.com #账号
set smtp-auth-password=password #授权码
set smtp-auth=login

3.命令列傳送郵件測試

echo "测试邮件" | mail -s '请在明天下午联系我' 111@qq.com

此時在PHP腳本中呼叫mail函數,會傳回false,開啟錯誤日誌,顯示:

May 23 13:09:26 localhost sendmail[3901]: NOQUEUE: SYSERR(php-fpm): /etc/mail/sendmail.cf: line 0: cannot open: Permission denied

因為我們還沒開啟對於httpd發送郵件的支援

4.開啟httpd發送郵件支援

setsebool -P httpd_can_sendmail 1

5.假如出現dsn:service unavailable錯誤,需要修改hostname

hostname <hostname> #假如是本地服务器,尝试设置为本地IP地址

推薦學習:php影片教學

以上是為了使用郵箱服務,php7該如何設定sendmail的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除