|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
# m& `, x: h( a5 c% e* H& j3 v首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
+ ?& O% N- V2 x: P然后打开php.ini文件,找到下面这段代码+ C8 U% z$ n2 ]6 Y% {
- [mail function]
% x- ~* {/ ]& p! Z- f - ; For Win32 only.
4 p7 R! M2 v" c) s4 @, w- B3 c - SMTP = localhost $ L2 c2 B- o! L
- smtp_port = 25
% r3 R8 m0 Q O6 L - ; For Win32 only.
3 }7 T/ P. w9 F+ ?. A) e - ;sendmail_from = me@example.com
) f7 _8 Z! k* n - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
! n+ l; x1 U( z) P! ~3 e( x/ w - ; sendmail_path = ""
7 Y4 L6 \6 Q9 Q3 C* w! x- o b$ E - ; Force the addition of the specified parameters to be passed as extra parameters
& U& p/ G+ { y+ t, M" f - ; to the sendmail binary. These parameters will always replace the value of
7 s* C8 m* W3 n; m# v9 I0 c - ; the 5th parameter to mail(), even in safe mode.
9 M( X; `7 U# j1 d - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
. N0 V9 f# B7 G- [mail function]
! X. i% x: G" H9 b - ; For Win32 only.
r" S) ?3 P2 @ - ;SMTP = localhost
* f5 \6 I3 _" [' {4 b6 U7 ? - ;smtp_port = 25
2 Y: O b% Q9 [, g2 ^ - ; For Win32 only.
( c# C- m! u% _# q0 X9 Y - ;sendmail_from = me@example.com 8 o) t3 c1 w; o4 @: L
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). V0 [" Y* @; U: P, B
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" 0 i2 N: F* M0 N" p) h( _# t
- ; Force the addition of the specified parameters to be passed as extra parameters - Z# C" L$ z- r6 B1 X" I% h0 p7 ?
- ; to the sendmail binary. These parameters will always replace the value of 3 B& R5 d4 i& r7 m* x# {
- ; the 5th parameter to mail(), even in safe mode. 3 Z/ U! ^* U1 }$ S& T# |
- ;mail.force_extra_parameters =
复制代码 + i2 t6 e9 R: V& ~
注意以上只需要开启sendmail_path即可,然后保存 0 C5 J. P% S( j) _9 [. t* `7 N3 W
3 R; C4 |2 W: t }+ Y6 G! N& E
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
- {/ z7 D" z, ]: Z. M; i- }9 f- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
! D& z4 C+ W8 R7 C6 Q - auth_username=邮箱登录名(如 info@xxxx.com) - A4 |; z/ C+ T1 ^
- auth_password=邮箱密码(如 xxxxxx)
, j D2 ]( u1 ]( N" }2 { - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项 # q, x1 X- |! P3 q3 `; A/ p3 b
- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 $ X; } M3 b$ G! A' t* k0 U
把前面的";"删除,即开启SSL安全登录选项即可 ; J0 E: M) V: x. }! I; c
: _( y: E# q+ \' C1 |8 T/ b) w
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
. Z% W- `) ^ T
1 ], C# ?2 i: u2 N3 `如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
. h/ s* h) e* J; @$ h. c2 [
{, h* v2 p! T2 C. B |
|