|
|
最近研究uchome,使用在线发邮件的功能,但是测试了"通过 PHP 函数的 sendmail 发送(推荐此方式)"怎么都没用,因为本人现在用的是iis+php环境,怎么调试都没有用,经过研究之后搞定,分享一下教大家在自己服务器上配置sendmail。很多php的网站例如Discuz的论坛和各种phpCMS的网站都用到。
) E6 s$ `. O) n& z( o+ t! M首先你需要先到从http://glob.com.au/sendmail/下载sendmail.zip文件,点此可以直接下载噢,然后把它解压到如D:\php\sendmail\目录下。
! ~* w. Q. H# Q" q5 l然后打开php.ini文件,找到下面这段代码& ^5 M% |2 t( l# ?
- [mail function]
, ]9 Q: k# I4 H- ? - ; For Win32 only.
/ i9 [9 f+ j: l - SMTP = localhost
2 {2 G9 O+ l' i5 c7 a' @" r3 @ - smtp_port = 25 j+ Y' f2 I) M0 Z5 M
- ; For Win32 only. 8 x2 T! |( X6 n, P/ `/ Q* s( B, F0 [
- ;sendmail_from = me@example.com # c% O+ L) g/ |& _# q3 }
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
' p ?7 Q" I; o2 e - ; sendmail_path = "" 1 w, F, K7 J! E; ?9 e4 N
- ; Force the addition of the specified parameters to be passed as extra parameters " M- {, T4 _$ t* S& a B6 B
- ; to the sendmail binary. These parameters will always replace the value of
6 }2 l6 |8 y/ E+ O |7 E - ; the 5th parameter to mail(), even in safe mode. 8 m( X/ H; o/ H4 C
- ;mail.force_extra_parameters =
复制代码 默认情况下是以本机做为邮件服务器,这里我们需要借用sendmail来发送邮件,用sendmail来配置如用qq、163的邮箱来发送(一般都是以这种方式)所以我们需要把所有的选项都注销,即把SMTP = localhost和smtp_port = 25前面加上";"然后把sendmai_path=""前面的";"删掉,改为sendmai_path="d:\php\sendmail\sendmail.exe -t",改完后的即是 - }9 E k" H7 ~. i/ r4 q
- [mail function] 3 w. z1 l1 V* f; Y
- ; For Win32 only. - {. N3 u3 a; Y9 e4 q2 B% Y
- ;SMTP = localhost 1 U: k6 z( x3 B& y/ I' H; L2 W1 w! U
- ;smtp_port = 25
# G4 B1 ~8 l5 }! Q$ t - ; For Win32 only. $ F7 l- l8 m% D) J# Y- s$ J5 n
- ;sendmail_from = me@example.com 7 ^- k7 z& z& e! M. K& j! z
- ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
9 q0 a& h' M+ P: n5 n9 A3 P - sendmail_path = "d:\php\sendmail\sendmail.exe -t"
2 p6 e& G9 W" j ~ r/ U+ E - ; Force the addition of the specified parameters to be passed as extra parameters
! a; q/ C/ A R - ; to the sendmail binary. These parameters will always replace the value of ) S0 J& y7 Q# @
- ; the 5th parameter to mail(), even in safe mode.
6 m4 y0 k% |: \ - ;mail.force_extra_parameters =
复制代码 ! U- H2 f* a% @+ f2 R5 e/ d1 B: |
注意以上只需要开启sendmail_path即可,然后保存 3 O2 }2 q' S1 }
9 v% }! y6 T/ ^+ l. ^9 K7 D
接着修改sendmail目录下的sendmail.ini文件,主要填的内容有以下几项 3 ]- @' q1 W2 i# c7 j
- smtp_server=smtp服务器地址(如 smtp.ym.163.com) / M# B; W2 k$ a; S
- auth_username=邮箱登录名(如 info@xxxx.com)
[/ Z" X7 U [ - auth_password=邮箱密码(如 xxxxxx)
5 t o) v1 v( ]0 ^- h - force_sender=发件人地址全写(如 info@xxxx.com)
复制代码 另外还有一项
. Q6 Q. i% u/ d# @; O5 b+ e5 m- ; auto = use SSL for port 465, otherwise try to use TLS
复制代码 8 p- z, S1 F' `; k
把前面的";"删除,即开启SSL安全登录选项即可 + o& \( D# o. L8 [* t6 `. k
. @: J7 ]' E% ~# D& K- H( `5 V以上四项正确填写修改完成后保存,然后重启IIS即可正常使用。 3 D q8 K, D6 W) i( V
) @5 o1 V2 F" q5 H" s
如果不能发送邮件,检查下端口是不是被屏蔽了,杀毒软件是不是设置了禁止发送邮件等 $ p: Y. [0 |) ]
$ k7 Y6 O- M( {% _1 O$ _5 Y
|
|