Home > Backend Development > PHP Tutorial > Windwos下PHP如何利用smtp服务本地发送邮件

Windwos下PHP如何利用smtp服务本地发送邮件

WBOY
Release: 2016-06-20 13:01:55
Original
1222 people have browsed it

PHP如何利用smtp服务本地发送邮件

linux 下情况比这要容易的多,下面讲一下windows下PHP如何利用smtp服务本地发送邮件的。

这需要修改php.ini 配置文件,需要一个额外的 sendmail.exe 支持下。因为php mail()函数在windows不能用,需要安装sendmail。

1.从 http://glob.com.au/sendmail/  下载sendmail.zip

2.解压到任何目录下,例如这里放到 D:\php\extras\sendmail,路径短点没有空格最好,否则可能容易产生未知的问题。

3.配置php.ini ,搜索 smtp,然后修改

[mail function]
; For Win32 only.
SMTP = 你的邮箱提供的smtp服务
smtp_port = 25
                     
; For Win32 only.
sendmail_from = 你的邮箱地址
                     
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "D:\PHP\extras\sendmail\sendmail.exe -t"
Copy after login

注意,这里的smtp要自己去查,我这里用的是网易的邮箱,具体邮箱的smtp配置都可以查到。

例如网易的邮箱:http://help.163.com/09/1130/15/5PCLK6AI00753VBA.html?b12ene1

有的可能还需要在邮箱里打开smtp服务:

注意最后那句,要配置:

sendmail_path = "D:\PHP\extras\sendmail\sendmail.exe -t"
Copy after login

4.然后打开sendmail.ini 配置sendmail

其他跟 php.ini 很像,这里主要介绍下:

auth_username= 你的邮箱地址
auth_password= 你的邮箱的密码
Copy after login

还有最后的

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content
      
force_sender= 你的邮箱地址
Copy after login

配置完了,就可以用php自带的mail函数测试啦:

mail($to, $subject, $message, $headers);
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template