Windows下配置用mail()發(fā)送郵件,以qq郵箱為例

php mail()函數(shù)在windows不能用,需要安裝sendmail,假如是用的XAMPP,則已經(jīng)下載好,不需要重新下載

參考資料:

qq郵箱開啟smtp服務(wù):https://jingyan.baidu.com/album/f00622283113c9fbd3f0c8d4.html?picindex=1

QQ郵箱的POP3與SMTP服務(wù)器是什么: http://service.mail.qq.com/cgi-bin/help?subtype=1&no=167&id=28ECS

解決windows系統(tǒng)下php.ini郵件配置正確不發(fā)送郵件的問題:https://help.aliyun.com/knowledge_detail/40745.html?spm=5176.11065259.1996646101.searchclickresult.4b74ac30dME0B4

解決方案


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

2.解壓到E:下,例如:【E:\sendmail】最好短路徑,長路徑名有可能產(chǎn)生問題。?

3.修改【php.ini】如下 (測試時(shí)用的是qq的郵箱)

[mail function]

; For Win32 only.

SMTP =?smtp.qq.com

smtp_port =?465

sendmail_from =?1004100390@qq.com

sendmail_path = “E:\sendmail\sendmail.exe -t”

*重啟apache服務(wù)

4.修改【sendmail.ini】如下。

[sendmail]

smtp_server=?smtp.qq.com

smtp_port=?465

auth_username=1004100390@qq.com

auth_password=password

force_sender=1004100390@qq.com

*用sendmail結(jié)合其它的smtp服務(wù)器,如smtp.qq.com來實(shí)現(xiàn)發(fā)郵件。現(xiàn)在大部分郵箱都要求smtp驗(yàn)證,所以要在sendmail.ini中加入用戶名和密碼。

username是你的郵箱賬號,password是授權(quán)碼,需要你在qq郵箱開啟smtp服務(wù),他會給你一個(gè)授權(quán)碼,(必須開啟否則無效,開啟方法見參考資料)


5.PHP代碼

$headers = "From:webmaster@example.com" . "\r\n" ."CC:somebodyelse@example.com";

//發(fā)件人 ?以及 抄送

$rs=mail("674094877@qq.com","My subject","ceshi content",$headers);

if($rs){

????echo "success";

}else{

????echo "error";

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容