PHP的bbs实现之三

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:  邮件发送功能实现: sql语句: CREATE TABLE ourmail2 (  email_addr  varchar(40) NOT NULL,  create_time  var...

 邮件发送功能实现:

sql语句:

CREATE TABLE ourmail2 (
  email_addr  varchar(40) NOT NULL,
  create_time  varchar(20),
  PRIMARY KEY (email_addr),
  UNIQUE email_addr (email_addr)
);

1.editemail.php

<?                                                                                              
/********************************                                                               
*运行两个外部的程序             *                                                               
*其作用是定义一些常用的变量     *                                                               
*和CSS的显示类                  *                                                               
*并进行和goldenwind数据库的连接 *                                                               
*********************************/                                                              
 include "header.inc.php";                                                                      
 include "common.inc.php";                                                                      
?>                                                                                              
                                                                                                
<HTML>                                                                                          
<!--html的头定义-->                                                                             
<HEAD>                                                                                          
  <TITLE>                                                                                       
     发送邮件                                                                                   
  </TITLE>                                                                                      
</HEAD>                                                                                         
                                                                                                
<BODY>                                                                                          
                                                                                                
<!--显示网页中的大标题-->                                                                       
<p align=center>                                                                                
  <font size=5 color=red >                                                                      
      发送一个新的邮件                                                                          
  </font>                                                                                       
</p>                                                                                            
                                                                                                
<hr color=red>                                                                                  
                                                                                                
<?                                                                                              
/********************************                                                               
*下面是用户的输入表单           *                                                               
*用户在此填写电子邮件的内容     *                                                               
*填写完毕后调用发送程序         *                                                               
*********************************/                                                              
?>                                                                                              
<FORM ACTION="postemail.php" METHOD="post">                                                     
  <TABLE width=80% border=1  align=center bgcolor=yellow>                                       
    <TR class=myBlack bgcolor=green>                                                            
      <TD colspan=2 height=20 align=center>                                                     
          <FONT class=myYellow>                                                                 
             请按照要求填写下列各项!                                                           
          </FONT>                                                                               
      </td>                                                                                     
    </TR>                                                                                       
    <!--输入昵称-->                                                                             
    <TR class=myBlack>                                                                          
      <TD height=20 width=20% align=center class=myRed>邮件标题:</TD>                           
      <TD height=20 width=60% align=center>                                                     
        <input type="text" name="subject" size=50>                                              
      </TD>                                                                                     
    </TR>                                                                                       
    <TR class=myBlack>                                                                          
      <TD height=20 width=20% align=center class=myRed>邮件内容:</TD>                           
      <TD height=20 width=60% align=center>                                                     
          <textarea name="newemail" cols=50 rows=10 wrap=virtual></textarea>                    
      </TD>                                                                                     
    </TR>                                                                                       
                                                                                                
    <!--输入时的选择按钮-->                                                                     
    <TR class=myBlack>                                                                          
      <TD height=30 width=80% colspan=2 align=center class=myRed><BR>                           
        <INPUT type=reset  name=Start value=" 重置 " class=myBlack>                   
        <INPUT type=submit name=Ok value=" 发送 " class=myBlack>                     
      </TD>                                                                                     
    </TR>                                                                                       
  </TABLE>                                                                                      
                                                                                                
</FORM>                                                                                         
                                                                                                
<!--显示版权等信息,使用的是CSS标记-->                                                          
<DIV class=myGreen align=center>                                                                
    <? echo $COPYRIGHT; ?>                                                                      
</DIV>                                                                                          
<BR>                                                                                            
                                                                                                
</BODY>                                                                                         
</HTML>                                                                                         

2.maillist.php

<?                                                                                           
include "common.inc.php";                                                                    
                                                                                             
if ($Ok)                                                                                     
  {                                                                                          
   if ($choice=="sub")                                                                       
      {                                                                                      
        if (!ereg('^[-!#$%&/'*+//./0-9=?A-Z^_`a-z{|}~]+'.                                    
        '@'.                                                                                 
        '[-!#$%&/'*+///0-9=?A-Z^_`a-z{|}~]+/.'.                                              
        '[-!#$%&/'*+//./0-9=?A-Z^_`a-z{|}~]+$', $myemail))                                   
          {                                                                                  
             header("Location: login_error.php?error=邮件地址输入错误/n");                   
          }                                                                                  
        $email_check = "select email_addr from ourmail                                       
          where email_addr = '$myemail'";                                                    
        $check_result = mysql_query($email_check)                                            
         or die("不能执行地e-mail地址的检查。");                                             
        $check_num = mysql_num_rows($check_result);                                          
        if ($check_num == 0)                                                                 
        {                                                                                    
             $create_date = date("Y-m-d");                                                   
             $sql = "insert into ourmail                                                     
                  values('$myemail', '$create_date')";                                       
                                                                                             
             @mysql_query($sql) or die ("Can't add this  email address.");                   
             header("Location: on_ok.php?log_id=$log_id/n");                                 
         }                                                                                   
         else                                                                                
         {                                                                                   
              header("Location: login_error.php?error=你已经订阅过了!/n");                  
         }                                                                                   
       }                                                                                     
    else                                                                                     
    if  ($choice == "unsub")                                                                 
        {                                                                                    
          $email_check = "select email_addr from ourmail                                     
              where email_addr = '$myemail'";                                                
          $check_result = mysql_query($email_check)                                          
              or die("不能执行对e-mail地址的检查。");                                        
          $check_num = mysql_num_rows($check_result);                                        
          if ($check_num == 0)                                                               
            {                                                                                
              header("Location: login_error.php?error=输入的e-mail不存在。/n");              
             }                                                                               
          else                                                                               
            {                                                                                
              $email_dele = "delete from ourmail                                             
                  where email_addr = '$myemail'";                                            
              @mysql_query($email_dele) or die ("Can't delete this email address");          
             header("Location: on_ok.php?log_id=$log_id/n");                                 
             }                                                                               
         }                                                                                   
     }                                                                                       
 include "header.inc.php";                                                                   
?>                                                                                           
                                                                                             
<BODY>                                                                                       
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">                                          
  <TABLE width=60% border=0 align=center bgcolor=yellow>                                     
    <TR  bgcolor=green>                                                                      
      <TD height=20 align=center>                                                            
           <FONT  class=myYellow>                                                            
             欢迎加入社区的邮件列表!                                                        
          </FONT>                                                                            
      </TD>                                                                                  
    </TR>                                                                                    
    <TR >                                                                                    
      <TD height=50 align=center>您的邮件地址:                                              
        <INPUT type=text name=myemail size=40 maxlength=40>                                  
      </TD>                                                                                  
    </TR>                                                                                    
    <TR>                                                                                     
      <td width="50%" align=center class=myRed>                                              
        <input type="radio" name="choice" value="sub" checked>                               
        订&nbsp&nbsp阅&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp                                         
        &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp                                            
        <input type="radio" name="choice" value="unsub" >                                    
        退&nbsp&nbsp定&nbsp&nbsp </td>                                                       
    </TR>                                                                                    
    <TR>                                                                                     
      <TD height=20 align=center>                                                            
        <INPUT type=submit name=Ok value=" 提交 " class=myBlack>                   
        <INPUT type=reset name=Back value=" 还原 " class=myBlack>                            
      </TD>                                                                                  
    </TR>                                                                                    
                                                                                             
  </TABLE>                                                                                   
</FORM>                                                                                      
<DIV class=myGreen align=center>                                                             
    <? echo $COPYRIGHT; ?>                                                                   
</DIV>                                                                                       
<BR>                                                                                         
                                                                                             
</BODY>                                                                                      
</HTML>                                                                                      

3. postemail.php

<?                                                               
//如果邮件标题或者正文为空则重新输入                             
if (($subject =="") || ($newemail == ""))                        
  {                                                              
    header("Location: http://localhost/editemail.php");          
    exit;                                                        
  }                                                              
else                                                             
  {                                                              
                                                                 
  // 连接数据库                                                  
  $db = mysql_connect("localhost", "root")                       
     or die ("不能连接。");                                      
                                                                 
  //选择社区数据库                                               
  mysql_select_db("goldenwind", $db) or die ("不能选择数据库。");
                                                                 
  //查找邮件地址                                                 
  $sql = "select email_addr from ourmail";                       
  $res = mysql_query($sql) or die("不能得到邮件地址。");         
                                                                 
  //定义附加的邮件头                                             
  $headers = "From: fecit@fecit.com/n";                          
                                                                 
/********************************                                
*使用while循环来多次发送邮件    *                                
*每次从数据库中取一个地址       *                                
*然后调用mail函数来发送邮件     *                                
*********************************/                               
  while ($row = mysql_fetch_array($res))                         
    {                                                            
       //取出下一个邮件地址                                      
        $email_addr = $row[0];                                   
       //发送电子邮件                                            
        mail("$email_addr", "$subject", $newemail, $headers);    
    }                                                            
//返回成功信息                                                   
header("Location: on_ok.php?ok_info=邮件成功发送/n");            
}                                                                
?>                                                               

4. search_mail.php

<html>                                                                        
<!--html的头定义-->                                                           
<head>                                                                        
   <title>                                                                    
      查看邮件列表                                                            
   </title>                                                                   
</head>                                                                       
                                                                              
<body>                                                                        
                                                                              
<?                                                                            
/********************************                                             
*运行两个外部的程序             *                                             
*其作用是定义一些常用的变量     *                                             
*和CSS的显示类                  *                                             
*并进行和goldenwind数据库的连接 *                                             
*********************************/                                            
include "header.inc.php";                                                     
include "common.inc.php";                                                     
                                                                              
//从数据库中获取邮件列表的数目                                                
$count=mysql_query("select count(*) from ourmail where email_addr like '%@%'");
$count_row = mysql_fetch_row($count);                                         
?>                                                                            
<!--显示网页中的大标题-->                                                     
<p align=center>                                                              
   <strong>                                                                   
       <FONT size=5 color=red>                                                
       邮件地址列表                                                           
       </FONT>                                                                
    </strong>                                                                 
</p>                                                                          
                                                                              
<hr color=red>                                                                
                                                                              
<?                                                                            
/********************************                                             
*邮件列表查询的结果放在         *                                             
*表格中。表格有三项:           *                                             
*序号、邮件地址和创建时间       *                                             
*********************************/                                            
//显示表格的题头                                                              
?>                                                                            
<table border=1>                                                              
<TABLE width=80% border=1  align=center bgcolor=yellow>                       
   <TR class=myBlack bgcolor=green>                                           
      <TD colspan=3 height=20 align=center>                                   
          <FONT class=myYellow>                                               
             <? echo "共有".$count_row[0]."条纪录/n"; ?>                      
         </FONT>                                                              
      </td>                                                                   
   </TR>                                                                      
<?                                                                            
//循环显示邮件列表的每一项                                                    
$i=1;                                                                         
$result=mysql_query("SELECT * FROM ourmail where email_addr like '%@%'");     
while ($row=mysql_fetch_array($result))                                       
{  echo "<tr><td height=20 width=5% align=center class=myBlue>"               
        .$i."</td>/n";                                                        
   echo "<td height=20 width=20% align=center class=myRed>"                   
        .$row["email_addr"]."</td>/n";                                        
   echo "<td height=20 width=20% align=center class=myRed>"                   
        .$row["create_time"]."</td></tr>/n";                                  
   $i++;                                                                      
}                                                                             
echo "</table>/n";                                                            
?>                                                                            
                                                                              
<!--显示版权信息-->                                                           
<DIV class=myGreen align=center>                                              
    <? echo $COPYRIGHT; ?>                                                    
</DIV>                                                                        
                                                                              
</body>                                                                       
</html>                                                                       

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
存储 算法 PHP
唯一ID生成原理与PHP实现-雪花算法
唯一ID生成原理与PHP实现-雪花算法
675 0
唯一ID生成原理与PHP实现-雪花算法
|
缓存 移动开发 NoSQL
php结合redis实现高并发下的抢购、秒杀功能的实例
php结合redis实现高并发下的抢购、秒杀功能的实例
269 0
|
PHP
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
525 0
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
|
网络协议 Linux 网络安全
php实现websocket实时消息推送
php实现websocket实时消息推送
550 0
php实现websocket实时消息推送
|
PHP
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
221 0
|
PHP
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
439 0
|
消息中间件 PHP Windows
PHP实现php-amqplib/php-amqplib实例RabbitMq
PHP实现php-amqplib/php-amqplib实例RabbitMq
304 0
|
XML 移动开发 JSON
PHP使用yansongda/pay实现支付宝和微信的支付
PHP使用yansongda/pay实现支付宝和微信的支付
1099 0
|
NoSQL PHP Redis
PHP结合redis实现点赞功能
PHP结合redis实现点赞功能
152 0
|
消息中间件 缓存 JSON
PHP实现think-queue介绍
PHP实现think-queue介绍
439 0