|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。9 M- m$ a" ~- Z
首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
% u& x( p* H& s8 ?; v w然后打开php.ini文件,找到下面这段代码
! K0 Y j3 ~3 D! S/ C# S- [mail function] % U$ T/ v# w/ F* f, x" w1 V7 w% o
- ; For Win32 only. 4 ?6 s) f0 ~; I! O
- SMTP = localhost
$ _+ p1 a5 X0 @- Z7 j - smtp_port = 25 9 E+ N) k$ c% D6 H' n
- ; For Win32 only.
+ C) J, o! y: N9 U - ;sendmail_from = me@example.com
8 {7 k H* x; C, g0 w u2 W - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). $ b& Z+ K! q5 R8 f
- ; sendmail_path = "" % Q7 K% O8 b0 K8 l* j) q% N
- ; Force the addition of the specified parameters to be passed as extra parameters 0 I: {6 V' G' ]
- ; to the sendmail binary. These parameters will always replace the value of 5 m0 b. R( N8 O) g) C
- ; the 5th parameter to mail(), even in safe mode.
0 @1 P8 A3 a( M: s1 Z% C+ X" \ - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 ' a$ |2 X W6 {; b E q5 v9 P
- [mail function]
0 P; Z& `4 u6 N1 b+ M2 E6 x. h - ; For Win32 only.
) y+ w$ X% R; a$ a( F. I( Y& k3 Z - ;SMTP = localhost
; r# Q) j9 a; N% V e4 Y - ;smtp_port = 25 / u# W8 ~/ S; F* [; z# |( U# `1 M4 \
- ; For Win32 only. + U9 P- [1 w) M. Z1 x
- ;sendmail_from = me@example.com 3 a; M* G6 o) e9 d
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 7 B A& ?0 F2 P. v
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" : x; D2 o8 }" f
- ; Force the addition of the specified parameters to be passed as extra parameters
: }* s" c7 T0 m1 u& ] - ; to the sendmail binary. These parameters will always replace the value of
- u! z4 S+ N) A( S - ; the 5th parameter to mail(), even in safe mode.
' Z' a( U8 e# Y G% q5 F J" c( c - ;mail.force_extra_parameters =
复制代码
: V. Q- I! u. o7 w$ X- r注意以上只需要开启sendmail_path即可,然后保存
* n& R6 t0 G) I5 H6 G/ z2 W- E- l4 c
& \+ z5 B0 s. u, N" E! o0 P% L }接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
6 v: C) B6 q% P' F6 a- smtp_server=smtp服务器地址(如 smtp.ym.163.com) , K- v9 W2 k; S6 r2 S# j
- auth_username=邮箱登录名(如 info@xxxx.com)
1 d; Y. ~. d& `6 c& u0 r9 T; l - auth_password=邮箱密码(如 xxxxxx) # Q) v% W4 l, d
- force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项 " z2 y9 T& T- A* Y) r6 x# I
- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
1 k( f, _8 q+ M* \% z0 A) `把前面的";"删除,即开启SSL安全登录选项即可
9 Z- l" r+ i7 T. y; A" B# A
% D+ c! a6 Y5 ^ g2 m: W以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 1 R( @$ R! ^3 `' M4 f
9 f8 s% `% ?, H( `- J1 X如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
3 ], X9 }+ O% m
- s1 I4 C S( {/ H; _( Y& a4 X |
|