|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
b! ~. [, o6 U7 a) y# ^6 u首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。- u u% @# _* m/ W4 Q% u7 g: k
然后打开php.ini文件,找到下面这段代码
& s5 i0 d2 q4 z; J4 |+ O, ]- [mail function] $ R1 z& C+ n% X `# \
- ; For Win32 only. 6 r- H; ?" P: O+ E; f5 p! P
- SMTP = localhost + a6 l1 P7 b' D* w
- smtp_port = 25 ' @8 ^; M [0 U3 z! D D. R1 ~
- ; For Win32 only.
2 P9 E9 U0 a; m - ;sendmail_from = me@example.com ! D4 O' v f4 d
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). & J+ Z; O1 m% I- @; ~/ A' p, \
- ; sendmail_path = ""
: M, ]4 E0 ^3 Y; I5 q% r1 z/ h - ; Force the addition of the specified parameters to be passed as extra parameters : _. J5 f& T7 q& i. R+ H8 ?5 a& @
- ; to the sendmail binary. These parameters will always replace the value of
! f0 H7 h6 g0 K - ; the 5th parameter to mail(), even in safe mode.
5 G* J) D$ q3 E, T - ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 * W( }! V- I" K4 k5 t; N5 {
- [mail function]
4 i5 S2 _* L/ G$ J6 u+ Z - ; For Win32 only.
# Q4 Y9 R6 z" |$ Y - ;SMTP = localhost
) R" q" X( T, ~" M. h - ;smtp_port = 25 * l+ y5 w! ?; N) m+ e" b9 ~$ v
- ; For Win32 only.
9 @! }1 e2 C! d6 Q% m' m$ ~ - ;sendmail_from = me@example.com $ r; h. E. o9 }1 a9 A+ m
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ' I% O3 U8 y9 x
- sendmail_path = "d:\php\sendmail\sendmail.exe -t" 1 n% u* f9 W2 b' k
- ; Force the addition of the specified parameters to be passed as extra parameters % K P0 d3 {4 t
- ; to the sendmail binary. These parameters will always replace the value of
9 E4 l# i5 U; A9 g+ S - ; the 5th parameter to mail(), even in safe mode.
! a, E, s; ]" o9 p% h1 c - ;mail.force_extra_parameters =
复制代码
0 ^; u6 ^# E* [, s& Y" \6 O/ M7 \注意以上只需要开启sendmail_path即可,然后保存
. R" k; H7 C$ f) [9 g; V
( F: [9 K& X) \接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项 % d0 g7 _) s: _6 |
- smtp_server=smtp服务器地址(如 smtp.ym.163.com)
% s+ e# D3 J) D& O2 D. i6 S3 \2 ~ - auth_username=邮箱登录名(如 info@xxxx.com)
6 W5 w7 M) A+ m6 \/ A7 o3 [ - auth_password=邮箱密码(如 xxxxxx)
5 V/ z0 l2 M$ r1 O - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
$ g- s7 W, U' R- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码
0 Q9 G* f% \4 |把前面的";"删除,即开启SSL安全登录选项即可
- |1 R) D- _# r# z4 l* e7 k( K6 i) y
以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 4 l4 x9 X1 w1 t/ z, J O4 Q
' n7 q" B; r! J8 k# R如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 ' D! _6 E8 O% }
6 l1 `7 d y8 n; P3 U |
|