php mail()函數在windows不能用,須要安裝sendmail。php
1. 從http://glob.com.au下載sendmail.ziphtml
2. 解壓sendmail.zip到目錄下(最好使用短路徑,長路徑會致使問題的出現),我安裝的路徑是: E:\wamp\sendmailwindows
3.修改php.ini 配置,我是使用的QQ郵箱發送郵件。配置以下圖所示:函數
4.修改 sendmail.ini,文件路徑:E:\wamp\sendmail\sendmail.ini測試
smtp_server=smtp.qq.com
smtp_port=25
auth_username=yourusername
auth_password=yourpassword
force_sender=*****@qq.com
下面這兩項最好開啓,方便查看那裏出問題了 spa
; 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
5.測試發送郵件功能debug
1 <?php 2 header("Content-type:text/html;charset=utf-8"); 3 4 if(mail("test@test.com","測試","測試郵件")){ 5 echo "發送成功!!"; 6 }else{ 7 echo "發送失敗!!"; 8 } 9 10 ?>