PHP mail()函数

mail()函数,你能用此函数发送电子邮件。
语法:
bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])
在上面的语法中的各个参数代表的意思是:string to——收件人的email地址、string subject——email的主题、string message——email的正文、string additional_headers——加email的附加信息到信件头尾部。
如果邮件成功的被发送mail()函数将返回TRUE,否则返回FALSE。

Windows下配置PHP的邮件发送或者使用sendmail for windows

mail函数在win里可以通过配置php.ini来正常使用
打开php.ini

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = me@example.com
; 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 = me@example.com
; 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压缩包

解压后找个地方放好,将里面sendmail.exe的地址填到sendmail_path并如上面所写增加-t -i参数(更多参数自己查吧)。
打开:sendmail.ini文件
修改里面的

smtp_server=smtp服务器地址
auth_username=邮箱登录名
auth_password=邮箱密码
force_sender=发件人地址全写

ok了mail函数可以正常使用了,注意如果iis使用cgi模式运行php的话用sendmail方法会出错,修改为ISAPI模式后一切正常了。