Windwos下PHP如何利用smtp服務本地發送郵件

來源:互聯網
上載者:User
PHP如何利用smtp服務本地發送郵件

linux 下情況比這要容易的多,下面講一下windows下PHP如何利用smtp服務本地發送郵件的。

這需要修改php.ini 設定檔,需要一個額外的 sendmail.exe 支援下。因為php mail()函數在windows不能用,需要安裝sendmail。

1.從 http://glob.com.au/sendmail/ 下載sendmail.zip

2.解壓到任何目錄下,例如這裡放到 D:\php\extras\sendmail,路徑短點沒有空格最好,否則可能容易產生未知的問題。

3.配置php.ini ,搜尋 smtp,然後修改

[mail function]; For Win32 only.SMTP = 你的郵箱提供的smtp服務smtp_port = 25                     ; For Win32 only.sendmail_from = 你的郵箱地址                     ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").sendmail_path = "D:\PHP\extras\sendmail\sendmail.exe -t"

注意,這裡的smtp要自己去查,我這裡用的是網易的郵箱,具體郵箱的smtp配置都可以查到。

例如網易的郵箱:http://help.163.com/09/1130/15/5PCLK6AI00753VBA.html?b12ene1

有的可能還需要在郵箱裡開啟smtp服務:

注意最後那句,要配置:

sendmail_path = "D:\PHP\extras\sendmail\sendmail.exe -t"

4.然後開啟sendmail.ini 配置sendmail

其他跟 php.ini 很像,這裡主要介紹下:

auth_username= 你的郵箱地址auth_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= 你的郵箱地址

配置完了,就可以用php內建的mail函數測試啦:

mail($to, $subject, $message, $headers);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.