|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
W3 Q( ~9 ]$ `% `' t$ r9 s首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。) M; x, v2 P. U+ |
然后打开php.ini文件,找到下面这段代码
/ Q I6 D# e" J# h4 @; M- [mail function]
( \9 U: m- w' x& H0 `! w0 ~) { - ; For Win32 only.
) Q% a% U7 T. M$ E - SMTP = localhost ' T$ l7 T1 j1 Q
- smtp_port = 25 # Q6 U, P: y! E0 r
- ; For Win32 only. 4 d: C& m8 S8 L0 u$ b
- ;sendmail_from = me@example.com
9 H# o3 I' Q/ _- b8 U" {" T - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 6 I7 Z2 ?7 y6 k7 |
- ; sendmail_path = ""
w0 |$ r* d) n0 p7 X - ; Force the addition of the specified parameters to be passed as extra parameters " z+ u# O# Q: Z& u* F
- ; to the sendmail binary. These parameters will always replace the value of
9 c' s4 [4 @9 ]4 K" o3 C6 w: K" o, Q! ? - ; the 5th parameter to mail(), even in safe mode.
+ }+ m$ i1 z1 O' Z - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
2 Q' U% A7 N* L4 F. D- M- [mail function] " a+ ?' {$ ?$ |$ S0 f- V- z# C
- ; For Win32 only.
% B. q. ~% S7 x' g4 }$ ~5 { - ;SMTP = localhost 0 |8 R! T. K, N9 {( r+ b
- ;smtp_port = 25
5 K0 Z+ g a" t( F! ^& {# G. n - ; For Win32 only. & M6 L! j1 K/ U' S
- ;sendmail_from = me@example.com P! Z' Z. x# W' @0 R8 e/ f
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). + n& T! }0 t9 n2 M6 H _ Q$ M
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" : j5 b! I2 n! k: k- q9 r7 F
- ; Force the addition of the specified parameters to be passed as extra parameters $ x+ W3 Z. i6 Q! O
- ; to the sendmail binary. These parameters will always replace the value of
. I {+ r' K. c; `6 a( b* K - ; the 5th parameter to mail(), even in safe mode.
9 }5 U8 G! v1 @$ p - ;mail.force_extra_parameters =
复制代码
4 t5 \% [* E- X% R, X( z8 m注意以上只需要开启sendmail_path即可,然后保存 0 I2 Z9 f3 c+ E; _0 {9 `2 d+ k/ L
$ `* r4 q1 ?. i I4 K
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项 j2 r8 _: @: ~6 ~
- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
& Y1 y# n6 R2 q2 R0 z0 Y4 p - auth_username=邮箱登录名(如 info@xxxx.com)
3 H4 r6 ]$ [- c0 l) [, j - auth_password=邮箱密码(如 xxxxxx)
. h6 q2 d1 m P/ H* R/ R - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
: n# I5 _; z) X1 Z- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
2 c' q4 ^+ r! L% @7 s% E$ [把前面的";"删除,即开启SSL安全登录选项即可
7 e- k4 ~$ o2 N
2 n- J) A5 m2 C5 s+ _以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
) v& f9 v' ]! V M$ ^4 h/ O, z8 [' e% ^; D( Z0 H5 E
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 , H" P/ S/ x7 {2 H4 H! r, a
, S8 X. F ` u. G: ]- y1 o |
|