今天主要实现了成功发送邮件的功能。利用mail.php文件进行修饰。利于on个mail()函数实现发送邮件的功能,下面讲今天写的代码与大家分享一下:
require_once('email.class.php');
include("dbconnect.php");
if(isset($_POST['op'])){
function check_form($form){
if(!get_magic_quotes_gpc()){
foreach($form as $key=>$value){
$form[$key] = addslashes($value);
}
}
return $form;
}
$form = check_form($_POST['edit']);
extract($form);
$sql = "insert into tbl_reg values(null,'{$name}','{$pass}','0',md5('{$name}'))";
$mail = $_POST['edit']['mail'];
echo $mail."<br>";
mysql_query($sql);
$sql1="select mdname from tbl_reg where username='{$name}'";
$res=mysql_query($sql1);
$row = mysql_fetch_array($res);
echo $row['mdname'];
$smtpserver = "smtp.163.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "jiandan0117@163.com";//发信人
@$smtpemailto = $mail;//收信人
$smtpuser = "jiandan0117@163.com";//smtp.163.com需要验证
$smtppass = "liudan19921213";
$mailsubject = "验证码";
@$mailbody = "<a href=http://localhost/seven/huiyuan/do_reg.php?name=".$row['mdname'].">点击http://localhost/seven/huiyuan/do_reg.php?name=".$row['mdname']."</a>";
$mailtype = "HTML";
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
$smtp->debug = FALSE;
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
?>
<!--action=“可以为当前页面,也可以为另外一个独立的php页面”-->
<form action="reg.php" method="post" id="user_register">
<!--数据表not null的字段形成对应的input-->
用户名:<input type="text" name="edit[name]" id="edit-name" size="30" vaule="abc"/>
<BR>
口令:<input type="password" name="edit[pass]" id="edit-pass" size="30" />
<BR>
确认口令:<input type="password" name="edit[pass2]" id="edit-pass2" size="30" />
<BR>
mail:<input type="text" name="edit[mail]" id="edit-mail">
<BR>
<!--提交按钮,同步交互-->
<!--javascript验证各项信息的有效性:第一种 <form ... οnsubmit="return check_form();"> 第二种 <input ... οnclick="return check_form();">-->
<input type="submit" name="op" value="register" οnclick="return check_form();"/>
</form>
<!--定义用户注册表单验证js函数,利用正则表达式实现有效性的检验-->
<script>
function check_form(){
//使用getElementById方法得到指定名称的标签元素
//标签元素的值对应的属性value
//IE浏览器打开后自动生成window对象,document对象是window对象 //的基本属性,window.document 等于 document
username = document.getElementById("edit-name").value;
password = document.getElementById("edit-pass").value;
password2 =document.getElementById("edit-pass2").value;
msg = "";
<?php
//$_POST
//$sql=mysql_query("select * from tbl_reg where username=".."")
?>
if(username==""){msg+="username is not null! \n"}
if(password==""){msg+="password is not null! \n"}
if(password!=password2){msg+="must equal! \n"}
if(msg!=""){
return false;
}else{
return true;
}
alert(msg);
}
</script>