PHP发送电子邮件

来源:互联网 发布:日本研究生知乎 编辑:程序博客网 时间:2024/06/13 11:20

今天学习了PHP的mail函数,并且利用它发送发送一些简单点的邮件,下面 开始吧:

1、首先,应该配置自己的PHP文件(也就是php.ini文件)然后需要安装sendmail

   可以在我的百度网盘下载:http://pan.baidu.com/s/1c0jApig

2、下载后将其解压到任意一个目录下面,我的是和php相关文件放在一起了(自己建立一个文件夹sendmail),比如放在 F:\AppServ\php6\sendmail下面

3、修改php.ini文件如下:(这个文件可以搜到,好像在C:windows下面)
sendmail_path = "F:\AppServ\php6\sendmail\sendmail.exe -t"修改为这样

4、重启Apache

5、用sendmail结合其他的smtp服务器,如smtp.163.com来实现发邮件,现在大部分需要验证,所以还需要配置一下sendmail.ini文件,加入用户名和密码

6、修改php.ini文件如下:

[mail function]
; For Win32 only.
SMTP = smtp.163.com
smtp_port = 25
; For Win32 only.
sendmail_from = 54561612@163.com
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "F:\AppServ\php6\sendmail\sendmail.exe -t" 

7、sendmail.ini 配置如下:

[sendmail]
smtp_server=smtp.163.com
; smtp port (normally 25)
smtp_port=25
smtp_ssl=auto
;default_domain=mydomain.com
error_logfile=error.log
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=
54561612@163.com

auth_password=这里写你的163邮箱密码。。。。


好!!配置信息完成了,下面写一段php代码吧:

建立EmailDemo.php文件:

<html><?php   $name = "马建杰";   $email = $_POST['email'];   $feedback = $_POST['feedback'];      $totaladdress = "15227290166@163.com";   //收件地址   $subject = "反馈";//邮件主题      $emailcontent = "顾客 名字:".$name."\n".//邮件内容                    "顾客 email:".$email."\n"."顾客评论:\n".$feedback."\n";   $fromaddress = "From: 592357262@qq.com";      mail($totaladdress,$subject,$emailcontent,$fromaddress);     //发送邮件?><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>邮件发送</title></head><body><h1>提交反馈</h1><p>你的反馈已经发送</p></body></html>    

运行程序就OK啦!!


2 0
原创粉丝点击