|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
, K/ L! t8 r: S3 f" i1 s& A; L首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。( O1 W$ m& r; n
然后打开php.ini文件,找到下面这段代码
8 N9 u( r Q" V; R9 q$ O- [mail function]
2 Z3 V. }) |3 m0 N) F/ }9 b/ L - ; For Win32 only. ) i4 i9 s8 }4 ^! |
- SMTP = localhost
6 D8 q; t' K# F' N - smtp_port = 25
! V6 y9 ?9 ^: v# T9 ~/ u. [ - ; For Win32 only. ! @" \4 R: e* @& Q* U9 o
- ;sendmail_from = me@example.com
3 P# ~* _6 y$ |$ u% w/ k - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
2 B5 E" r, ^6 K9 v - ; sendmail_path = "" ; j' E: Z+ e- S" W. A. {) y
- ; Force the addition of the specified parameters to be passed as extra parameters
2 ~6 L2 F( Q0 s) w2 i, r - ; to the sendmail binary. These parameters will always replace the value of
3 S# N5 k, y* D( R9 w, w - ; the 5th parameter to mail(), even in safe mode. , P3 w- R2 P- n- v
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
. A# f2 M4 m4 }# ^- l/ ~- [mail function]
+ y% H& E9 v$ D$ s. _ - ; For Win32 only. 2 E6 a8 S# L/ r
- ;SMTP = localhost
) S5 |3 n8 y; V9 R1 k; F* Z - ;smtp_port = 25 % e% w6 z" X, h) x A7 ~9 u" k
- ; For Win32 only.
5 ?# Q, Y' _# l8 z# y! ]6 K - ;sendmail_from = me@example.com
$ f( T: z4 L: K/ [( A& w8 U0 H - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
& I! ~+ ~0 E9 q `6 s5 H I - sendmail_path = "d:\php\sendmail\sendmail.exe -t" 4 K/ U) i7 F& R8 z+ ?
- ; Force the addition of the specified parameters to be passed as extra parameters
* V$ D' [9 W3 X: Y5 }6 J8 \ - ; to the sendmail binary. These parameters will always replace the value of
' K& T; D: K; R9 [. ^! Y" T - ; the 5th parameter to mail(), even in safe mode.
0 ?3 T0 @1 j9 j4 Q ] - ;mail.force_extra_parameters =
复制代码 ( M$ R# Z! [& C, e
注意以上只需要开启sendmail_path即可,然后保存
. ?, X' z. \' N3 W0 d
# A) v3 |) T; ?' P: P接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
9 b+ p* U& z# j- smtp_server=smtp服务器地址(如 smtp.ym.163.com) 4 j1 J9 T6 T# E+ y" K& C
- auth_username=邮箱登录名(如 info@xxxx.com) - s5 A4 h; x- R( I+ Z6 }& J! Y+ {9 N
- auth_password=邮箱密码(如 xxxxxx)
0 g# ^* z* p" Q- x3 o - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
7 m* A( d1 N2 d" E: `7 K6 L! m- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
- `0 _/ U* o7 K* [' o把前面的";"删除,即开启SSL安全登录选项即可 ! u3 F$ j3 w+ E, G1 F1 D) ^) N
' n) m2 | }) p. `; i7 r以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
E6 ~& o; X) M) d( I2 |* w0 _1 }! H* P
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 7 n F6 l* M! |* J: |6 v& U
4 l: B- S( o5 U1 p
|
|