|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
/ f5 v7 o( F+ F2 D3 s: J首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
( M) J, [2 z6 v0 @然后打开php.ini文件,找到下面这段代码
" P$ R j* u8 u- [mail function]
& i6 j8 R& X1 c - ; For Win32 only.
7 i% J+ x5 q* ] - SMTP = localhost ( u! e0 S7 |; Q1 E% ~6 e
- smtp_port = 25
. f5 N. |& R8 e5 }* g, p - ; For Win32 only.
7 ^; z. W, k! h7 X2 e - ;sendmail_from = me@example.com
, a" }7 A# }% F: \4 Z2 K o - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
& D3 _: P1 y! e# d8 F1 \- P - ; sendmail_path = "" , g% ?1 U, ^' O6 R$ X8 ]! c
- ; Force the addition of the specified parameters to be passed as extra parameters
9 D% ~2 G7 x i2 M: H - ; to the sendmail binary. These parameters will always replace the value of
9 l( y s# v0 p1 y! t1 T1 l - ; the 5th parameter to mail(), even in safe mode.
+ l: p0 g$ R2 \ - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是
* g% Q. a8 ?9 U6 q ?1 J8 e- [mail function] 6 Z5 i4 u( w2 ^2 l8 `- R5 ]8 L
- ; For Win32 only. 6 w- R) ]0 {5 `! Y' I7 R" Z7 s
- ;SMTP = localhost $ I, y% }8 k4 v9 z1 ~( N/ f9 z
- ;smtp_port = 25 - r4 b# N5 R$ F! G) }: ?
- ; For Win32 only. : i! c% x" g! ]
- ;sendmail_from = me@example.com
7 ]0 I6 d# M- M6 O- ~) O - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
$ z6 U5 X/ Z& V% ?) n3 Q' N4 l' [ - sendmail_path = "d:\php\sendmail\sendmail.exe -t" ' H9 j: m0 m4 [, \. ~1 d
- ; Force the addition of the specified parameters to be passed as extra parameters
7 U4 [6 B7 N9 m$ O$ V% s H - ; to the sendmail binary. These parameters will always replace the value of ) Q: G3 z0 c" I4 E
- ; the 5th parameter to mail(), even in safe mode. * d2 P8 t. V9 S* K9 b
- ;mail.force_extra_parameters =
复制代码
, g7 O" l' R, ~: J0 ^5 C* w$ y注意以上只需要开启sendmail_path即可,然后保存
5 d/ x; z' k( @. c0 y& i6 ]" N: z3 B
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
) h% ?3 ~0 V2 S- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
3 ^6 O X) z* a8 V - auth_username=邮箱登录名(如 info@xxxx.com) 7 |6 q1 ?1 |& g6 {2 U
- auth_password=邮箱密码(如 xxxxxx)
! [7 s8 c% f2 j `- @ - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
. l& S+ Q: Q1 t8 c) k( J- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 $ j B% m+ r4 \: U9 ~+ \
把前面的";"删除,即开启SSL安全登录选项即可 6 O- T3 R( S0 W( V: w
6 X2 }4 ?6 r2 S
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 4 b) Y6 e0 [) W* E' ]) e
7 p1 O1 H y! K0 R如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 / z7 | x2 P, W" C8 s8 M
8 ^9 m- |9 e1 q2 M, u, N) K2 U
|
|