windows的php环境下使用sendmai的smtp功能l的简单配置

来源:互联网 发布:大数据时代的阅读答案 编辑:程序博客网 时间:2024/06/11 15:58

在一些场景下(最常见的就是注册账号时需要发送邮箱验证)需要使用到邮件发送功能,此时可以通过sendmail(一个邮件传输代理程序)实现。值得一提的是windows下的的配置和Linux下配置方法不同,虽然一般服务器都是部署在linux上,但也存在有和本人一样喜欢在windows下写代码调试的人

一、下载

配置之前,可以在网上自行搜索下载sendemail,懒一点的同学可以通过我的百度云下载

链接:http://pan.baidu.com/s/1slaUmpZ 密码:sq7y 

解压后建议将sendmail文件夹放在php的目录下


二、邮箱设置

在本文中,我就以163邮箱作为例子,好像163邮件默认是开启smtp服务的所以不用设置,其他邮箱如果不是默认开启的话可以通过网页登录邮箱后点击设置里面开启。(pop3和imap都是收信的协议,这里不是必须开启的)


三、php.ini的主要配置


; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
 ; http://php.net/sendmail-path
 sendmail_path ="D:\fwq\php7\sendmail\sendmail.exe -t" 这个地方填写的就是你自己文件夹解压后sendmail.exe的地址


四、sendmail.ini的配置

; 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


; if your smtp server requires authentication, modify the following two lines


auth_username=
auth_password=

这里填写你邮箱的账户密码


smtp_server=smtp.163.com   这个按照你的邮箱来定(也是在邮箱的设置地址里面看)

force_sender=                          这里还是填写邮箱账户


之后再使用php的Mail()类或者其他扩展类即可,若未发送成功可看错误日志,也要注意一下是否被当做垃圾邮件。



1 0