|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。- u2 h6 @% p4 s8 i- b
首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
9 A+ a! z& F3 W, r. R( q d# W然后打开php.ini文件,找到下面这段代码
4 [# ]3 |' R) s t0 P4 d W- [mail function]
& @: x- K Q4 p5 s! ^! T( F - ; For Win32 only.
) t% `0 G: Q. J6 U5 a - SMTP = localhost . V( C1 F( K; m- U8 O
- smtp_port = 25 2 Q* C0 H! |# s6 i8 U ^' j% _0 Q
- ; For Win32 only.
$ _: B/ b5 C0 c W* u1 y+ y! Y - ;sendmail_from = me@example.com
6 G3 W8 H' U* l+ `; B - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). * ]. N8 Q2 {, P9 i, W6 c: K* P
- ; sendmail_path = "" , c# U- o R+ e% l7 ~
- ; Force the addition of the specified parameters to be passed as extra parameters * ]! T4 D" m$ Y* D3 [0 q! }: B, x
- ; to the sendmail binary. These parameters will always replace the value of 5 n5 ~! c) t$ E0 g# ?
- ; the 5th parameter to mail(), even in safe mode. . Y( K& Q6 r- \3 z
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 ( z+ }7 p0 O. J$ ]
- [mail function] ! N' j+ Z/ {0 r4 Z3 P$ ?
- ; For Win32 only.
$ ^8 G% x) {' H: A# b1 W - ;SMTP = localhost # S; K3 q/ p. H$ L% C* b+ r, R
- ;smtp_port = 25
/ x0 q! i! E& v- b* P m - ; For Win32 only. f9 N3 H% z8 a2 Y3 X- x+ T+ P3 \9 [
- ;sendmail_from = me@example.com @4 o% c# v/ k4 V) A: n! u
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
+ y8 T0 x! h- \0 j6 g( f- M0 x: Z% }. S - sendmail_path = "d:\php\sendmail\sendmail.exe -t"
7 \# S8 w; `, W# d& N - ; Force the addition of the specified parameters to be passed as extra parameters
. K/ G" B8 o: y2 O, a3 _ - ; to the sendmail binary. These parameters will always replace the value of
1 z* x8 L" U: n, q% V - ; the 5th parameter to mail(), even in safe mode. 7 u. J V6 w2 E o) g
- ;mail.force_extra_parameters =
复制代码 2 j* A4 \% V L) k, ^+ U
注意以上只需要开启sendmail_path即可,然后保存
5 t" @9 |+ [8 s x0 O' w+ R. p4 d4 Q) o
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
- E# x* g7 K, n; {3 t* _- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
: e6 d5 |) t y& w - auth_username=邮箱登录名(如 info@xxxx.com) # L0 P$ z; o0 e5 h3 C7 T+ h. G) L
- auth_password=邮箱密码(如 xxxxxx)
' k+ V$ u3 C) l1 {8 Q6 f - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
# F8 ?( Q/ A0 y% C- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 2 P( L! u1 v8 y1 E; ?) e; d
把前面的";"删除,即开启SSL安全登录选项即可 & o1 X5 n0 `& J( Q& m2 A
# g% a) f/ P* w+ {0 ^# ]
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 ; [0 S1 x( w [/ C2 U- F
2 V+ S! X; P7 s9 P% B) R如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
5 ]& a7 F$ p9 X. @/ v5 e, o0 Y t
8 s4 ~# e! o5 r. l) Y$ A |
|