1 頁 (共 1 頁)

(OCS) 使用 php mail() 利用 gmail 發信 - fake sendmail for windows

發表於 : 2025-04-09, 11:04
dtchang
由於要取代PHP mail()為 phpmailer 有點複雜, 就改回使用 gmail發信 (禁用無加密的方式發信).

1. 需有 gmail 帳號
2. 申請 16 字元的程式密碼
Google 帳戶中的[安全性]/[二階段驗證]/「應用程式密碼(App Password)」設定頁面中,申請一個名稱(如: mail PHP)的密碼.
google回應彈出的密碼(要去掉空白)為16字元密碼(此密碼為應用程式專用,和google帳號登入的密碼無關)
3. 複制 google回應彈出的密碼, 並去掉空白 (這密碼只提供一次,故需立即複制)
3. 設定 fake sendmail for windows 的 sendmail.ini 及 php.ini
4. 本例限用 SSL, 故指定為 port 465
5. 本例中的 xxxxxx@g.chu.edu.tw 為學校配合 google 的專用 gmail 帳號,故名稱上沒有 gmail.com 字樣

代碼: 選擇全部

; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail

[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=smtp.gmail.com

smtp_port=465

; SMTPS (SSL) support
;   auto = use SSL for port 465, otherwise try to use TLS
;   ssl  = alway use SSL
;   tls  = always use TLS
;   none = never try to use SSL

smtp_ssl=on

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

;default_domain=mydomain.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

;debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username =xxxxxx@g.chu.edu.tw
auth_password =xxxxxxxxxxxxxxxx (16位不含空白的程式專用密碼)

; if your smtp server uses pop3 before smtp authentication, modify the 
; following three lines.  do not enable unless it is required.

;pop3_server=
;pop3_username=
;pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content

force_sender=

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify 
; the "To: " header of the message content

force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting.  you can manually set the ehlo/helo name if required

hostname=