|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
3 k* A" [: [7 U/ Z. t4 y- X7 ^首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。4 U0 ~" o( ^( w$ M) }% \
然后打开php.ini文件,找到下面这段代码
o( h7 f' d3 y0 a% a- [mail function]
" ?5 g0 l. g }' w - ; For Win32 only.
+ u3 \" [: |0 I5 {! f - SMTP = localhost
9 r3 _# i( c, a4 s7 k - smtp_port = 25 $ i1 k. @3 o& R( U4 Q$ k
- ; For Win32 only. & k' v1 d, z3 D/ t3 Y) K7 c
- ;sendmail_from = me@example.com
5 U2 e7 \) j( F. u- x. p - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
- S( n6 B& G& l- V. Q - ; sendmail_path = ""
" x7 s- D) y: r - ; Force the addition of the specified parameters to be passed as extra parameters . M) }, U( i/ I" t6 W# i# ^; [
- ; to the sendmail binary. These parameters will always replace the value of
5 L4 t, J' S2 y - ; the 5th parameter to mail(), even in safe mode. 2 Y4 q. r2 E5 e' E; f+ M+ u7 x
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 $ L$ R. u0 s T8 [ i t
- [mail function] 6 D3 Z# G( A7 d& p3 ^
- ; For Win32 only. + I* \% `. y! y/ U2 b$ C1 x7 t' J* T
- ;SMTP = localhost
9 N# Y9 Z- g7 @& o - ;smtp_port = 25
_9 X' d, k" @+ t J3 s - ; For Win32 only.
4 |$ p! m; W# n- u" Q; s3 g! Z - ;sendmail_from = me@example.com - {2 g' z" Q/ t4 y
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
' }" Z; O: Z' O# ]8 K - sendmail_path = "d:\php\sendmail\sendmail.exe -t" 0 ~3 `( C; D ]# y+ }; _
- ; Force the addition of the specified parameters to be passed as extra parameters
9 c% Z1 i7 o0 k% t$ @ - ; to the sendmail binary. These parameters will always replace the value of . L! p) W4 T" V4 k5 u
- ; the 5th parameter to mail(), even in safe mode.
" C+ r- Y8 T. G: B - ;mail.force_extra_parameters =
复制代码 8 `- U$ R0 M* `* m0 X0 h! w2 p7 S
注意以上只需要开启sendmail_path即可,然后保存
5 z% E5 h: a F, g4 D" p0 z3 H5 {2 H' R h# h6 T
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
2 [% F }) |7 _( e- smtp_server=smtp服务器地址(如 smtp.ym.163.com) # h1 r& Y! j7 G8 W$ S
- auth_username=邮箱登录名(如 info@xxxx.com) . d. U9 |( `1 l F/ A1 a
- auth_password=邮箱密码(如 xxxxxx) ! w2 c; S; t; s0 i2 m$ ^
- force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
2 q# Q: ~) x7 a2 ^- J' d" J+ v- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 " E: p" r3 Z! |) ~* c+ W
把前面的";"删除,即开启SSL安全登录选项即可 ( X; x: V! J" d- j: j+ m" S. i( s6 S. F, z
2 g: s: o' D: I* N9 X6 d以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
e# D$ `% @$ R) X
7 \# r% ?/ v% W. Y; X1 M; D( r T如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
$ I, ^- E; p- ^% ?6 f4 X& H `
- n* H$ B6 W; M |
|