|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
4 F/ d7 k* I" {4 D! _首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。 Y$ }, c) \4 j7 }% g% ]6 h2 \! c
然后打开php.ini文件,找到下面这段代码
$ G( k+ V* s E" u# i- [mail function]
, f2 f9 W; Z( R) v8 g3 u& A - ; For Win32 only. ) g* p$ U2 X# G* ]; _ x% u% y
- SMTP = localhost 6 j3 f) C5 g1 r% S) c
- smtp_port = 25
) @0 @- e2 t# s$ i3 ` - ; For Win32 only.
: X" s) P& [3 Q7 D - ;sendmail_from = me@example.com
E; g0 a, ^$ X6 z - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; y B' i( a/ J, J
- ; sendmail_path = "" 4 \) P7 l: R* _& C$ }% v; d; F
- ; Force the addition of the specified parameters to be passed as extra parameters
" i5 i0 \1 X2 T) s4 e$ i$ d - ; to the sendmail binary. These parameters will always replace the value of
5 X4 J2 X) y! L5 A9 z - ; the 5th parameter to mail(), even in safe mode. ! c: d4 _ d V2 C& t. o
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 ) H8 p y; Z6 c- N5 U6 v
- [mail function]
' m) `1 X1 o$ A$ V - ; For Win32 only.
& |7 g9 F6 n0 t, {- e7 O5 ` - ;SMTP = localhost
% U$ f& r4 Z l. w" b O - ;smtp_port = 25
4 O' n0 @( T, s& S1 @/ a9 x( z - ; For Win32 only.
. o9 J! U# m: A" b0 \ - ;sendmail_from = me@example.com
: w& P% P& O% G* D9 Y; \ - ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). , C7 t5 V, L- R- N0 w3 z
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" 8 c' |! R( D. p1 a" M
- ; Force the addition of the specified parameters to be passed as extra parameters ; E+ n' d6 q, e; v7 I: G
- ; to the sendmail binary. These parameters will always replace the value of
' @0 K( q2 }8 ^% j% Z2 L- \ - ; the 5th parameter to mail(), even in safe mode.
: M# E8 q. \: i- l; Y - ;mail.force_extra_parameters =
复制代码 - t0 f; r! [( ^) }: [0 _* K
注意以上只需要开启sendmail_path即可,然后保存 ' m P* U; d9 M* W9 d7 j2 w E
) |' }* ~: J- T8 Q+ z# C
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项
) j @, `" G5 S0 p) c" E, \- smtp_server=smtp服务器地址(如 smtp.ym.163.com) ( |4 u3 s$ p( V B% C F/ j7 C9 [
- auth_username=邮箱登录名(如 info@xxxx.com) 8 h! t b x( z8 S
- auth_password=邮箱密码(如 xxxxxx)
( U0 p, ?# |8 Q, s9 [9 w9 o - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
$ Y$ B& ?: @7 C0 u z+ D5 Q- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 ' F9 P1 W& F7 G6 L5 n7 w
把前面的";"删除,即开启SSL安全登录选项即可
: j& m6 \$ ?$ n2 ^# e( e, s2 T( w3 H8 e
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。
6 }' y K/ G& D H- O8 ]* e; _: f
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等
( Z8 n7 F, B5 l( T: I
1 y# B! f" J$ q& X7 {3 m |
|