html页
<form action="http://xxx/yanz.php" method="post">
<table>
<tr>
<td>邮箱</td><td><input type="text" name="mail_name">
<input type="hidden" name="mail_table" value="ceshi"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="dy" value="订阅">
<input type="submit" name="td" value="退订">
<input type="hidden" name="action" value="tj"></td>
</tr>
</table>
</form>
php页
<?php
include("conn.php");
include("phpmail.php");
if(isset($_POST['action']) && ($_POST['action']=="tj"))
{
$mail_table=$_POST['mail_table'];//获取邮箱
$md5=md5(rand(000000000,999999999));//设置随机码
$mail_name=$_POST['mail_name'];
if($mail_name=="")
{
echo "不能为空!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
exit;
}
function checkEmail($inAddress)
{
return (ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+",$inAddress));
}
if(!checkEmail($mail_name))
{
echo "请输入正确的邮箱地址!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
exit;
}//判断邮箱地址
if(isset($_POST['dy']) && $_POST['dy']="订阅")
{
$sql="select * from $mail_table where mail_name='$mail_name'";
$query=mysql_query($sql);
$row=mysql_fetch_row($query);
if($row)
{
echo "该邮件已存在!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
exit;
}//查看是否已经订阅
$mail_text="这个是订阅邮件,你收到邮件说明该邮箱可用,请点击下面的网站进行确认<br><a href=http://xxx/usermail/yzumail.php?qd=".$md5."&act=yz&a=".$mail_name."&t=".$mail_table.">http://xxx/usermail/yzumail.php?qd=".$md5."&act=yz&a=".$mail_name."&t=".$mail_table."</a>";
$sql="insert into $mail_table(mail_name,mail_ctime,mail_mark,mail_md5) values('$mail_name',now(),'2','$md5')";
$query=mysql_query($sql);
$s="select * from user_smtp where usmtp_id='1'";
$q=mysql_query($s);
$r=mysql_fetch_row($q);
if($query)
{
smtp_mail($mail_name, '订阅邮箱', 'NULL', 'abc',$mail_name,$r[3],$r[1],$r[2],$mail_text,$mail_table);
exit;
}
else
{
echo "添加出错,请重新添加!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
//echo "<a href=jit.php>2秒后会自动跳转到添加界面,如果没有自动跳转请点这里</a><meta http-equiv=refresh content=2;url=jit.php>";
exit;
}
}
if(isset($_POST['td']) && $_POST['td']="退订")
{
$sql="select * from $mail_table where mail_name='$mail_name'";
$query=mysql_query($sql);
$row=mysql_fetch_row($query);
if(!$row)
{
echo "该邮件不存在!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
//echo "<a href=jit.php>2秒后会自动跳转到添加界面,如果没有自动跳转请点这里</a><meta http-equiv=refresh content=2;url=jit.php>";
exit;
}
$mail_text="这个是退订确认邮件,你收到邮件说明该邮箱取消订阅,请点击下面的网站进行确认<br><a href=http://xxx/usermail/yzumail.php?qd=".$md5."&act=td&a=".$mail_name."&t=".$mail_table.">xxx/usermail/yzumail.php?qd=".$md5."&act=td&a=".$mail_name."&t=".$mail_table."</a>";
$sql="update $mail_table set mail_md5='$md5' where mail_name='$mail_name'";
$query=mysql_query($sql);
$s="select * from user_smtp where usmtp_id='1'";
$q=mysql_query($s);
$r=mysql_fetch_row($q);
if($query)
{
smtp_mail($mail_name, '退订邮箱', 'NULL', 'abc',$mail_name,$r[3],$r[1],$r[2],$mail_text,$mail_table);
exit;
}
else
{
echo "删除出错,请重新添加!<br>";
echo "<a href=\"/\" onclick=\"javascript:window.close(); return false;\">关闭窗口</a>";
//echo "<a href=jit.php>2秒后会自动跳转到添加界面,如果没有自动跳转请点这里</a><meta http-equiv=refresh content=2;url=jit.php>";
exit;
}
}
}
?>
再写一个页面获取随机码和邮箱,判断邮箱内保存的随机是否正确,正确则mark设为1,不正确返回错误