PHP在Windows based開發使用sendmail教學 [Fake Sendmail]
有在使用PHP的朋友應該都很清楚,在LINUX BASE的環境中,如果要使用PHP做電子郵件的寄送,都會用到Sendmail 這個軟體,我們在租用虛擬主機時只要是 Linux 主機都會提供這個功能,這個功能預設會被 Wordpress 或是 Joomla 等系統使用,但是在 Windows 上如果安裝 apache + php 時,卻無法使用 sendmail ,該如何使用 Sendmail 呢~
其實要使用 php 寄送信件,方法有很多種,有很多封裝過的套件,也可以預設在 php.ini 設定 SMTP Server 不過呢 Linux 主機通常會提供 Sendmail 的方式來寄送信件,而這個方法也大多預設在 Wordpress 或是 Joomla 使用。
在開始設定之前呢,總是會有緣由,通常在公司內部開發系統都會遇到mail寄送的問題,這時候第一個解決方案一定是找一台 SMTP Server 設定設定就可以繼續開發,但是問題是開發完成後又必須要上傳到客戶租用的虛擬空間,那麼這時候又必須要重新修改 SMTP 的主機位置,帳號,密碼等等,感覺有點多餘,既然未來的主機可以使用Sendmail,那我們就把 Windows 上的開發環境也把 Sendmail 的功能打開吧。
注意!在Linux上的Sendmail包含郵件寄送的功能,但是Winbase如果使用Sendmail的功能基本上是假造出來的,因此你還是必須要準備一台 SMTP Server,來做郵件的傳送功能。
STEP 1 :
我們必須要先到 http://glob.com.au/sendmail/
下載 Sendmail 的安裝檔 ( 有分手動安裝與自動安裝 )
corAusir 備份檔案下載 : http://files.corausir.org/files/sendmail.zip
在此講解使用手動安裝檔案 ※如果使用gmail請另外下載 SSL 加密連線檔
STEP 2 :
先在將要解壓縮的資料夾建立好 C:\usr\lib
在將 sendmail.zip 內的所有資料解壓縮到這個資料夾內
STEP 3 :
開啟 sendmail.ini 檔案並且設定你的 SMTP server 等相關資料
smtp_server= 你的smtp server位置 如 smtp.pchome.com.tw
auth_username= smtp寄送帳號
auth_password= smtp寄送密碼
這三個是比較重要的 其他 pop3 等相關資料也可以一同設定
STEP 4 :
開啟 php.ini 檔案
php.ini 檔案依照 apache 套件安裝不同而位置會不同
appserv 等大多數的位置會在 c:\windows\php.ini
而 zend server 的位置會在 c:\zend server安裝位置\etc\php.ini
開啟後搜尋 mail function 位置,修改以下資料
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25修改為
[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25代表我們將 smtp 郵寄方式關閉
接下來搜尋 sendmail_path 並且修改
;sendmail_path =
為
sendmail_path = c:\usr\lib\sendmail.exe –t
(注意要拿掉最前面的 ; 符號)
設定好後重新開啟 apacha 服務 !一定要重新啟動服務
STEP 5 :
重新啟動後,檢查 phpinfo 資料,並且確定 sendmail 區塊已經如我們所設定的資料
STEP 6 :
確認後就可以先使用 mail() 函式來測試看看是否正確寄送信件
mail.php
1 2 3 4 5 6 7 8 9 10 <?php $to = 'heydod---@hotmail.com'; $subject = 'the subject2'; $message = 'hello'; $headers = 'From: cwl----@pcb-sk.com.tw' . "\r\n" . 'Reply-To: cwl---@pcb-sk.com.tw' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); echo mail($to, $subject, $message, $headers); ?>如果正確設定 smtp server 後應可以正確寄送郵件。
當設定完成後,APPSERV也可以讓 wordpress 或是 joomla 正確寄送信件囉。不過設定 fake sendmail 最主要的原因是要方便開發的程式可以減少修改的幅度上傳到其他主機空間。
謝謝各位
參考資料來源:
http://wiki.uniformserver.com/index.php/Installing_Fake_Sendmail_for_Windows
如有錯誤請指教謝謝。
Random Posts
Loading…
目前並無相關文章









非常感谢您的资料,我终于也安装成功,能够发邮件了,mantis跟踪系统也能用了。
困擾許久,今天多上了一堂課,非常感謝!!
Such a type of blog post will definitely click to numerous viewers. A good article and useful for its written content. Many thanks for sharing it up!. I don’t usually reply to posts but I will in this case. WoW : ) A rise in Additional.
非常感謝您的分享
Hello! I consider utilizing too many characters in meta labels in HTML program code and which includes too quite a few keywords and phrases in the website’s articles are the most indecent SEO approaches.