Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

IIS 環境 PHP sendmail 配置指南:使用外部 SMTP (QQ/163/新浪) 發送郵件

編輯:關於伺服器

準備工作

  1. 下載 sendmail.zip,解壓至 D:\php\sendmail\。
  2. 確認 PHP 安裝路徑 (如 D:\php)。

修改 php.ini

[mail function]
;SMTP = localhost
;smtp_port = 25
;sendmail_from = me@example.com
sendmail_path = "D:\php\sendmail\sendmail.exe -t"
;mail.force_extra_parameters =
  • 註釋掉預設 SMTP、smtp_port。
  • 啟用 sendmail_path 指向 sendmail.exe -t (-t 表示從郵件標頭解析收件人)。

修改 sendmail.ini

smtp_server=smtp.qq.com
smtp_port=465
auth_username=your_email@qq.com
auth_password=your_auth_code
force_sender=your_email@qq.com

; 啟用 SSL (465 埠) 或 TLS (587 埠)
; auto = use SSL for port 465, otherwise try to use TLS
auto
  • auth_password:QQ 郵箱需填「授權碼」而非登入密碼;163/新浪同理。
  • force_sender:強制發件人地址,防止被拒收。

關鍵權限:cmd.exe 讀取權限

sendmail.exe 內部會調用 cmd.exe,需授予 IIS 執行身分 (IUSR、IIS_IUSRS、NETWORK SERVICE 或應用程式池身分) 對 C:\Windows\System32\cmd.exe 的 **讀取與執行** 權限,否則報錯:

Warning: mail() [function.mail]: Could not execute mail delivery program

測試腳本 (mail.php)

常見問題排查

  • 端口 465/587 被防火牆攔截 → 放行出站 TCP。
  • 授權碼錯誤 / 郵箱未開啟 SMTP 服務 → 郵箱設定中啟用 POP3/SMTP/IMAP。
  • PHP disable_functions 禁用了 mail → 移除禁用。
Copyright © Windows教程網 All Rights Reserved