今天根据书上php程序写了个例子,主要功能是发送mail,结果提示mail函数不支持。
原来
php中 mail()函数在windows不能用,需要安装sendmail。
具体步骤如下:
1.从http://glob.com.au/sendmail/下载sendmail.zip
2.解压到C:下,例如C:\PHP\sendmail,最好短路径,长路径名有可能产生问题。
3.修改php.ini如下
sendmail_path
4.根据你自己的配置环境修改sendmail.ini。
第一次最好启用debug.log_file,error_logfile,以查看sendmail是否生效。
5.重启apache
用sendmail结合其它的smtp服务器,如smtp.gmail.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。
php.ini配置
;
SMTP
smtp_port
;
sendmail_from
;
sendmail_path
就配置三项,smtp、smtp_port和sendmail_path
sendmail.ini配置
[sendmail]
;
smtp_server=smtp.126.com
smtp_port=25
auth_username=yourusername
auth_password=yourpassword
force_sender=jackywgw@126.com
;
sendmail网上有下的,如果你是用xampp,那里面直接就带了。
同时在虚拟主机的conf里加上这样一句(这不貌似不使用也没有关系)
php_admin_value
此邮件地址为用户的邮件地址,随便添。
终于搞定了。
processfeedback.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
"Customer comments:\n".$feedback."\n";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Bob's Auto Parts - Feedback Submitted</title>
</head>
<body>
<h1>Feedback submitted</h1>
<p>Your feedback has been sent.</p>
</body>
</html>