|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
6 L. K1 L7 r6 V5 B4 v3 H首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
@ C8 M1 L% [& O) Q' [2 X# M然后打开php.ini文件,找到下面这段代码
Z' |3 |# t' k5 u. p8 y7 {- [mail function]
$ i; I# d7 n# u, F& v4 E - ; For Win32 only. " H" [$ G0 C: k; A: F- T/ C' ~
- SMTP = localhost & o# k9 `% X, t% Q: ^
- smtp_port = 25
% S% R1 G n c$ n - ; For Win32 only.
# ?; L& e! |. w# s1 O - ;sendmail_from = me@example.com 9 K6 V( J4 H& x- o9 V. W
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ( x5 x/ q$ D/ U) y
- ; sendmail_path = "" $ f. o) P# t6 R$ p! X* m) p& F
- ; Force the addition of the specified parameters to be passed as extra parameters 1 j8 A( p5 x8 x/ T- B
- ; to the sendmail binary. These parameters will always replace the value of
3 m6 a! y2 }+ l" ?% ] - ; the 5th parameter to mail(), even in safe mode.
5 M' O4 o: } T" |- B - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
2 x4 L: }! m; D: Z- [mail function]
P1 C$ ]* L# r; N$ `0 z$ l - ; For Win32 only.
! M2 t1 G7 f7 `, A) z' b - ;SMTP = localhost
# f3 W# P. ]6 b" a. f+ Y8 l - ;smtp_port = 25 ! Z- F! x7 M9 q6 B Q0 M$ w
- ; For Win32 only.
- @! @( H' p; |) V# C - ;sendmail_from = me@example.com
% T" K0 b" v U* {, P k" v - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). + j4 n0 G1 |3 D# u
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" 2 K8 P& V0 s1 ]* _' B8 X: j
- ; Force the addition of the specified parameters to be passed as extra parameters 3 q5 {* ~9 \8 v: ^3 ]9 x
- ; to the sendmail binary. These parameters will always replace the value of
1 Z) e! `% m& H8 C0 r; A+ p" F$ r - ; the 5th parameter to mail(), even in safe mode.
/ C; Q9 k* h; P0 _; x4 l - ;mail.force_extra_parameters =
复制代码 7 ]' I) t# w+ o+ [6 |: G {
注意以上只需要开启sendmail_path即可,然后保存
3 L( u: I* _: E
0 p' ~' R" G1 F' ?3 g0 Q接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
8 w- T2 F! a( ^' i0 h; O4 p- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
' D- Z: \2 R! M* u - auth_username=邮箱登录名(如 info@xxxx.com) 2 c+ `6 ~: X# J3 ]( X5 ?- t
- auth_password=邮箱密码(如 xxxxxx) 8 f: b$ } e5 w- ]
- force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项 8 n1 d& r, x2 N7 ~" ?/ l9 m
- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 1 X5 n( I# B; _- N- O
把前面的";"删除,即开启SSL安全登录选项即可
( b; c( V8 G: r8 h3 N& h4 u4 z* [7 c& J& N
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
5 q$ ?5 ~' m# y: m! l f) q' c; O( }5 Z0 _
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 1 _# G! T3 d& K! A
# a; S" F. {! A, \/ ^) S
|
|