我在自己的Windows 7系统下安装了wampserver服务器,但是使用mail()函数发送邮件时却报错了,于是在网上看了mail()函数的手册和相关信息,发现可以使用很多方法实现php脚本发送邮件,暂时记录一个比较简单的:
1,下载sendmail.zip 地址:http://glob.com.au/sendmail/;
2,解压缩sendmail.zip到sendmail文件夹,并将该文件夹移动到c:\wamp\下;
3,打开php.ini,可先打开wamp,点击其图标php->php.ini找到该文件,打开即可,在里面搜索到
describe1:
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you@yourdomain
ps:请注意上面这些内容全部需要用;号注释掉!
describe2:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path ="C:\wamp\sendmail\sendmail.exe -t"
ps:上面这行填写的是sendmail的路径,将其告知php解析器
describe3:
; 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 =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log =
ps:以上(除了“mail.add_x_header = On”外),其余的也都要用;注释掉的!
4,在c:\wamp\sendmail\目录下找到sendmail.ini这个文件并打开,如下几个地方一定要修改,其他默认的地方不变即可:
smtp_server=SMTP服务器(例如smtp.qq.com或者smtp.163.com)
auto = use SSL for port 465, otherwise try to use TLS(去掉他前面本来有的 ; 号,表示启用SSL)
default_domain=mydomain.com变成 ;default_domain=mydomain.com(这个很重要,这个不弄的话,php不会报错,但是邮件确实发不出去!!!我尝试很久才知道)
auth_username=您的邮件服务器用户名(比如XX@qq.com,注意进入相关(如qq)邮箱开启SMTP服务)
auth_password=您的邮件服务器用户(授权)密码
force_sender=您的邮件服务器用户名(同auth_username)
这些全部做完后,您在自己本地写好php后使用wampsever服务器和sendmail服务器就可以成功地使用mail()函数发送邮件,这在论坛设计时候的评论,反馈等方面很有用。
原文:点击打开链接