|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
6 Z1 }/ g; N5 A首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。( c8 _4 d. ?9 N
然后打开php.ini文件,找到下面这段代码 h" m9 R' U5 s: A6 @
- [mail function] & z: M5 H H. f& `8 |- C4 ?5 ?7 L
- ; For Win32 only.
5 S; N. m x$ b# B; _7 K) k - SMTP = localhost ' Z7 j/ J+ c* X. n4 C
- smtp_port = 25
- @. d- q5 X6 t - ; For Win32 only. 9 F( n8 K+ ^% u
- ;sendmail_from = me@example.com
$ x7 G) ^7 N. N' Q' v - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
5 {. F: i$ d# ]) M; c* w3 m - ; sendmail_path = "" & q1 I! ^0 z6 L; {) ]+ q
- ; Force the addition of the specified parameters to be passed as extra parameters 3 V' w$ t4 U; J
- ; to the sendmail binary. These parameters will always replace the value of 6 L: M8 u7 F Z; {' `& i
- ; the 5th parameter to mail(), even in safe mode. % C6 w4 l3 g, {: T% V2 @
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
1 G) @2 T; {2 p# u# n$ I- [mail function]
7 L( v" X; c3 x3 Y: k% X) S; C - ; For Win32 only. * r# o; j- }: c" u& K1 B
- ;SMTP = localhost " M& k2 ~' x% f/ m
- ;smtp_port = 25
" h/ V2 o3 B, e# J, z; p$ q: y - ; For Win32 only.
# S3 c% r; u8 B - ;sendmail_from = me@example.com
- J0 C1 Q1 r9 S( {7 J: `) ~ - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; k1 k4 F# Q2 N
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" ; v* j$ v* e5 x
- ; Force the addition of the specified parameters to be passed as extra parameters 7 s% U; _" _) I: R# E4 c
- ; to the sendmail binary. These parameters will always replace the value of
% i6 {- U7 X9 J - ; the 5th parameter to mail(), even in safe mode.
1 k$ M! `! j! d$ e+ F3 I - ;mail.force_extra_parameters =
复制代码
9 Q+ N2 U. P' w- K注意以上只需要开启sendmail_path即可,然后保存
* C7 p% s; S. j; K3 o- S9 U9 g
5 e8 _4 U: H) M) r接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项 * D) _0 A7 P% C: j( U
- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
+ l L: k+ ~% m/ K6 A. r - auth_username=邮箱登录名(如 info@xxxx.com) 6 ^. B5 p* J* w0 O/ e, D+ U
- auth_password=邮箱密码(如 xxxxxx) 9 V7 i6 K9 l2 H
- force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项 6 K t7 n4 z n; h
- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
\) v! U8 {: \/ Y8 ]把前面的";"删除,即开启SSL安全登录选项即可 8 l: E7 U! v' A$ v- m
) e& t. U: [) Y2 N! g2 a以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 1 Y7 x1 ~. o5 Y1 `6 f
: ?& T) Q/ n) W; \
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
7 `% q; K/ N& s3 e9 T$ m* c
0 B0 f$ |6 [3 a' c* k& ` |
|