php mail()函數(shù)在windows中是不能直接使用的,需要安裝sendmail,假如是用的XAMPP,則已經(jīng)下載好,不需要重新下載
1.下載sendmail.zip 地址:http://glob.com.au/sendmail/
2.下載成功后解壓,并把下載好的文件剪切至wamp目錄(其實存到哪里都一樣這里為了方便存就放在wamp下好了,和www在同一目錄)
3.配置php.ini 和剛剛下載的 sendmail/sendmail.ini
①php.ini
搜索[mail function]關(guān)鍵字找到如下代碼
[mail function] ; For Win32 only. ; http://php.net/smtp SMTP = smtp.qq.com ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from =798932948@qq.com ; For Unix only. You may supply arguments as well (default: “sendmail -t -i”). ; http://php.net/sendmail-path sendmail_path =”E:wampwamp64sendmailsendmail.exe -t”
SMTP = 郵箱smtp地址 (例:QQ郵箱是smtp.qq.com l63郵箱是smtp.163.com )
sendmail_from = 你對應(yīng)郵箱的郵件地址(例:QQ郵箱)
sendmail_path = 下載的sendmail中sendmail.exe的地址(例:E:wampwamp64sendmailsendmail.exe -t)
注意:去掉sendmail_path 前的分號,這里分號表示注釋的意思
改完之后重啟服務(wù)器配置才會生效
②sendmail.ini
因為我是用QQ郵箱,QQ郵箱不能直接使用密碼,要使用QQ授權(quán)碼
(什么是QQ郵箱授權(quán)碼?)
[sendmail] ; you must change mail.mydomain.com to your smtp server smtp_server=smtp.qq.com smtp_port=25 auth_username=798932948@qq.com auth_password=QQ郵箱授權(quán)碼 force_sender=798932948@qq.com
4.然后就可以用php中的mail()發(fā)送郵件了
例子localhost/mail.php
<?php $to = “收件人郵箱賬號”; $subject = “THEME”;//主題 $message = “Hello Email”;//郵件內(nèi)容 $from = “798932948@qq.com”; $headers = “From: $from”; $result = mail($to,$subject,$message,$headers); var_dump($result); ?>
如果,你對上面的內(nèi)容還有疑問,推薦選擇西部數(shù)碼企業(yè)云郵箱!有專人協(xié)助您解答郵箱疑問。
西部數(shù)碼21年老牌服務(wù)商,企業(yè)郵箱功能豐富,如定時發(fā)送、支持層級子文件夾,郵件撤回,日程微信通知、多彩便簽等幾十項特色功能,使用管理便捷。按需自由定制,購買靈活,PCIe加速、極速收發(fā)!而且支持小程序收發(fā)郵件,隨時隨地移動辦公。價格實惠,還可以免費試用!
高性價比企業(yè)郵箱開通鏈接:http://www.bingfeng168.cn/services/mail/