首頁 > PHP, 網頁設計 > PHP在Windows based開發使用sendmail教學 [Fake Sendmail]

PHP在Windows based開發使用sendmail教學 [Fake Sendmail]

2010年5月22日  瀏覽次數 : 3,739

有在使用PHP的朋友應該都很清楚,在LINUX BASE的環境中,如果要使用PHP做電子郵件的寄送,都會用到Sendmail 這個軟體,我們在租用虛擬主機時只要是 Linux 主機都會提供這個功能,這個功能預設會被 Wordpress 或是 Joomla 等系統使用,但是在 Windows 上如果安裝 apache + php 時,卻無法使用 sendmail ,該如何使用 Sendmail 呢~

image 租用虛擬主機時廠商都會提供 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 內的所有資料解壓縮到這個資料夾內

image

STEP 3 :

開啟 sendmail.ini 檔案並且設定你的 SMTP server 等相關資料

smtp_server=  你的smtp server位置 如 smtp.pchome.com.tw

auth_username= smtp寄送帳號

auth_password= smtp寄送密碼

這三個是比較重要的 其他 pop3 等相關資料也可以一同設定

image

 

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 服務 !一定要重新啟動服務

image

STEP 5 :

重新啟動後,檢查 phpinfo 資料,並且確定 sendmail 區塊已經如我們所設定的資料

image

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://glob.com.au/sendmail/

http://www.simplehelp.net/2008/08/25/how-to-install-and-setup-apache-mysql-and-php-in-windows/zh_TW/#sendmail

http://wiki.uniformserver.com/index.php/Installing_Fake_Sendmail_for_Windows

如有錯誤請指教謝謝。

Random Posts

Loading…

:: 把這篇好文推到書籤網站與更多人分享吧 ::
  • funp
  • Hemidemi
  • YahooKimo
  • Google
  • udn
  • Haohao
  • Live

目前並無相關文章

Ausir PHP, 網頁設計 , , , , ,

  1. 2010年11月20日17:31 | #1

    非常感谢您的资料,我终于也安装成功,能够发邮件了,mantis跟踪系统也能用了。

  2. Small
    2011年2月24日19:47 | #2

    困擾許久,今天多上了一堂課,非常感謝!!

  3. 2011年5月12日06:12 | #3

    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.

  4. sohodavis
    2011年6月3日03:48 | #4

    非常感謝您的分享

  5. 2011年6月3日17:06 | #5

    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.

  1. 本篇文章目前尚無任何 trackbacks 和 pingbacks。