|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
4 n) V- A0 b+ `$ V; U首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
$ L4 R9 e& G1 t6 d然后打开php.ini文件,找到下面这段代码
7 a. ^! g* V. U- `( k- [mail function]
# c/ S5 V. Q8 y( U" q6 w6 h) w' s - ; For Win32 only. ) q& }0 Z9 t6 F8 X% q' I& k
- SMTP = localhost $ Z4 o4 ~$ O* V* M4 x2 T: G
- smtp_port = 25
: a) l* `1 _; p; @ h, i - ; For Win32 only.
9 j% M2 g9 x" U - ;sendmail_from = me@example.com
5 P" q* w7 I; X+ z9 } - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 4 p. y6 M6 x, n- w, J
- ; sendmail_path = ""
) _3 k4 p& s1 M9 U' Y6 v. C - ; Force the addition of the specified parameters to be passed as extra parameters ; |0 ?: V" S8 y k2 N3 a3 `: F7 b, w) F
- ; to the sendmail binary. These parameters will always replace the value of
+ d3 c2 I) ?% h2 i( O) B) X4 | - ; the 5th parameter to mail(), even in safe mode. 0 }- S1 U9 f, S1 Z0 \8 [ A) i
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 " k; f! G7 o3 W' [! }8 l( c: d. v6 M
- [mail function] , [3 _- ]# N/ [' `& T
- ; For Win32 only. 6 e$ o0 i' O, z7 T- ^7 `. l% c2 \, g
- ;SMTP = localhost 7 a/ I6 y- w+ U5 l1 R2 G3 |) R% l2 | F
- ;smtp_port = 25 7 n' W0 q% F) }) i6 k
- ; For Win32 only.
. R& [: ~3 l0 ~! f - ;sendmail_from = me@example.com
$ e& h B0 m8 w" P - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
" a0 e! u) ~3 X3 Z% U - sendmail_path = "d:\php\sendmail\sendmail.exe -t"
% C9 D: {7 e# ]0 g- h l5 ] - ; Force the addition of the specified parameters to be passed as extra parameters ; |$ m/ n$ E! R' G
- ; to the sendmail binary. These parameters will always replace the value of - m- ]; [( [$ |1 P
- ; the 5th parameter to mail(), even in safe mode.
L6 [% ]( x/ v% E8 O4 o8 ?& l; `$ \" I - ;mail.force_extra_parameters =
复制代码 t! c) C+ q K( P0 Z1 L
注意以上只需要开启sendmail_path即可,然后保存
' e* H& E( U4 }
% K+ q# \; Z9 x2 U2 { `8 K, O2 N接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
% _9 F" m- S; {- ^% B) s- smtp_server=smtp服务器地址(如 smtp.ym.163.com) 3 v! O0 {- V9 e9 S% f# M$ J
- auth_username=邮箱登录名(如 info@xxxx.com) 0 U+ F- V$ \7 X/ v; ]0 D
- auth_password=邮箱密码(如 xxxxxx)
# A+ h- K. @% I4 Q& Y2 | - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
5 K; g" d4 }% _: A- B1 |- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 g* Q4 F& c' P
把前面的";"删除,即开启SSL安全登录选项即可
% N/ Y3 v; l' A% H* c( B
8 T) w- v# ]6 M: x以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
& V, S' r# n) U& B4 L" X* P. x. ]5 W7 \& u' h1 J
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
8 p) u' W3 Q$ g
0 h& l+ @6 x2 F. c |
|