|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
# A( T: g' n3 V: l6 q$ _# y首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
, G$ ~4 D+ L) u9 L. i然后打开php.ini文件,找到下面这段代码
" H) g' J/ e( N, C- [mail function]
) B- g; }7 n2 ?7 a# ~$ ~ - ; For Win32 only.
p: a3 t& Y2 B- }6 o - SMTP = localhost % S; k7 ~& S J
- smtp_port = 25 / H5 q k" @7 n7 \$ y6 z2 [
- ; For Win32 only. ' ~! c3 @ U0 _5 l i
- ;sendmail_from = me@example.com . ^+ c7 z6 M+ ~
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). . q7 [5 p; H! w0 l. \
- ; sendmail_path = "" " `5 w# _/ Q7 B& ?6 G* P
- ; Force the addition of the specified parameters to be passed as extra parameters
' `+ _! l# m t# i' Q3 U- @ - ; to the sendmail binary. These parameters will always replace the value of 8 U/ o% `6 k; x: N* X2 }% _
- ; the 5th parameter to mail(), even in safe mode.
e- n$ e, j+ C5 g$ w - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
4 @$ \; P' A% o# e/ `9 P7 ?6 y$ S- [mail function] - A) f1 E$ o$ F7 R \
- ; For Win32 only. 5 T( |7 S2 V4 B
- ;SMTP = localhost , }2 f6 A$ H5 [8 t
- ;smtp_port = 25 8 J& N; D4 ]+ Q, ^( Z5 I
- ; For Win32 only.
7 B8 _5 R# J3 k; E7 C7 T' m: w - ;sendmail_from = me@example.com
# U f6 O {* J/ |4 s - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 3 A' K! j) P& d N9 W) [
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" - R' a; g4 e/ P
- ; Force the addition of the specified parameters to be passed as extra parameters 9 p) |0 c* m! ^- a, P
- ; to the sendmail binary. These parameters will always replace the value of 2 p7 f! p" k4 a n7 R0 ]/ v" `8 {1 B
- ; the 5th parameter to mail(), even in safe mode.
( L' v" n. i* p& c - ;mail.force_extra_parameters =
复制代码 " V- B! }0 [/ \+ R- _" x% p
注意以上只需要开启sendmail_path即可,然后保存
7 a' M5 l m" N5 N2 S- a1 x0 x, x3 d5 {' I! ?4 f
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
6 W; p* k0 q& w5 D6 O* p1 C- smtp_server=smtp服务器地址(如 smtp.ym.163.com) 5 ~4 V" _1 A8 W: t! `' ~- U/ D
- auth_username=邮箱登录名(如 info@xxxx.com)
! \. k9 H% K" v- n: s8 l - auth_password=邮箱密码(如 xxxxxx)
6 l2 k5 R% E* V% t0 f0 ] y - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
9 |" {3 }2 G d. ?8 ]- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
5 x. W1 M0 c+ Y, e+ w把前面的";"删除,即开启SSL安全登录选项即可
4 m) ]" `4 ], {4 v! K' e; [
. Q, s( J" x: Q# p以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
( |! t6 b; e! u7 J* ]$ d% O: B/ y9 T3 x% O1 D% \7 X+ k: E6 i
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 , }( i& y2 R# P& i2 d
v" U! m8 \5 A) z
|
|