如何在Windows系统配置sendmail使用PHP的mail函数

如题所述

在Windows系统配置sendmail使用PHP的mail函数的方法:

    首先需要一个Sendmail组件,XAMPP套件里就有一个。把整个SendMail文件夹拷贝到合适的目录下,例如”D:/SendMail/”

2. 在php.ini中配置相应的sendmail参数:

[mail function]

; For Win32 only.

SMTP = smtp.163.com (如果同一台服务器上存在SMTP服务器,则可以保留localhost不变,否则,填写一个比较可靠的smtp服务器地址,例如163,gmail等)

smtp_port = 25   (如果服务器无需验证,则填写25端口;或者自架SMTP服务器,为了安全起见 ,另改一个通信端口号;或者使用启用ssl的smtp服务器,则填写465端口);

3. 同样,在sendmail目录下的sendmail.ini文件里,也要配置相应的参数,如果使用ssl方式的smtp服务器,需要填写这两个参数,分别把登录邮箱的用户名和密码设置进去就可以了。  

4. 如果需要输出调试信息,就需要把这两句前面的分号去掉,error.log里保存报错信息,debug.log里保存每一条发送记录。

;error_logfile=error.log

;debug_logfile=debug.log  

这样配置后就可以直接使用PHP自带的mail()函数来发送邮件了。

sendmail简介:

sendmail是最重要的邮件传输代理程序。理解电子邮件的工作模式是非常重要的。一般情况下,我们把电子邮件程序分解成用户代理,传输代理和投递代理。用户代理用来接受用户的指令,将用户的信件传送至信件传输代理,如:outlook express、foxmail等。而投递代理则从信件传输代理取得信件传送至最终用户的邮箱,如:procmail。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-08-03
php mail()函数在windows不能用,需要安装sendmail。
1.下载sendmail.zip
2.解压到C:下,例如C:\PHP\sendmail,最好短路径,长路径名有可能产生问题。
3.修改php.ini如下
sendmail_path = "C:\PHP\sendmail\sendmail.exe -t"
4.根据你自己的配置环境修改sendmail.ini。
第一次最好启用debug.log_file,error_logfile,以查看sendmail是否生效。
5.重启apache
用sendmail结合其它的smtp服务器,如smtp.gmail.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。

php.ini配置 (以用gmail邮箱为例)
[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25
; For Win32 only.
sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
sendmail_path = “C:\PHP\sendmail\sendmail.exe -t”
就配置三项,smtp、smtp_port和sendmail_path

sendmail.ini配置
[sendmail]
; you must change mail.mydomain.com to your smtp server
smtp_server=smtp.gmail.com
smtp_port=25
auth_username=yourusername
auth_password=yourpassword
[email protected]
; default_domain=mydomain.com
sendmail网上有下的,如果你是用xampp,那里面直接就带了。
同时在虚拟主机的httpd.conf里加上这样一句
<directory d:/www/users/username> php_admin_value sendmail_path ‘C:\PHP\sendmail\sendmail.exe -t [email protected]’</directory>
此邮件地址为用户的邮件地址,随便添。

------------------------

测试文件mail_test.php
<?
if(mail("[email protected]","测试","测试邮件"))
{
echo "发送成功!!";
}
else{
echo "发送失败!!";
}
?>本回答被提问者采纳
第2个回答  2017-04-07
要安装一个SMTP服务器(发邮件的服务器)才行,但建议你使用stmp.class.php类发邮件。
第3个回答  2017-01-08
注意:如果不是自己的服务器的话用其他方法。
mail函数在win里可以通过配置php.ini来正常使用
打开php.ini
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: ”sendmail -t -i”).
; sendmail_path = ”"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
设置SMTP,smtp_port,sendmail_from。分别是pop3服务器地址,端口号这两个一般默认,sendmail_from设置的是发件人邮箱
注意的是这里需要的pop3服务器是不需要身份验证的那种而且不能使用安全方式连接的。国内有些没有提供不验证服务的…在服务器上装上smtp组件就可以了,安装方法很多网上都有
如果不打算让本机成为smtp服务器,可以使用linux常用的sendmail,这样可以通过验证使用国内的一些服务器的pop3服务器,建议是qq或者foxmail个人感觉腾讯的速度和稳定都不错。
经测试目前163、新浪的SMTP无法使用,qq和foxmail可以用,其他没测试…

win下怎么配置呢
[mail function]
; For Win32 only.
; SMTP = localhost
; smtp_port = 25
; For Win32 only.
; sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: ”sendmail -t -i”).
sendmail_path = ”d:/soft/sendmail/sendmail.exe -t -i”
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

按上面的方式把前面说的三个选项前面都加上分号,把sendmail_path前面的分号去掉下载下面的文件:
sendmail压缩包
http://upload.server110.com/file/20131023/1-13102311152D32.rar
解压后找个地方放好,将里面sendmail.exe的地址填到sendmail_path并如上面所写增加-t -i参数(更多参数自己查吧)。
打开:sendmail.ini文件
修改里面的
smtp_server=smtp服务器地址
auth_username=邮箱登录名
auth_password=邮箱密码
force_sender=发件人地址全写
ok了mail函数可以正常使用了,注意如果iis使用cgi模式运行php的话用sendmail方法会出错,修改为ISAPI模式后一切正常了。
第4个回答  2016-09-29
这个和什么系统没关系,首先你的电脑需要有web的服务器环境,能当服务器,sendmail只要放到你的项目,然后安装官方配置下就可以使用了。
第5个回答  2016-10-10
找到windows下的Php.ini 文件打开它
修改配置:

具体操作你看这个详细说明吧

http://www.jb51.net/article/30166.htm