电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 网络编程 -> ASP教程
一个免费的邮件列表源程序(三)_asp实例
作者:网友供稿 点击:0
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 
Subscribe.asp
<%@ Language=JavaScript %>

<!--#include file = "include/SetGlobals.asp"-->
<!--#include file = "include/DBPath.asp"-->

<%
// output relevant meta tags
Init( "Subscription" );

// output common top of page
Header( <a href="work.asp">Work</a> --> Subscription, 3 );

// output page content
Content ( );

// output common bottom of page
Footer( );
%>

<% /* standard page elements */ %>
<!--#include file = "utils/Init.asp"-->
<!--#include file = "utils/Database.asp"-->
<!--#include file = "utils/Header.asp"-->
<!--#include file = "utils/Footer.asp"-->

<%
// ============================================
// the content of this page
// ============================================
function Content ( )
{
   Out ( <td width="20%">&nbsp;</td> );
   Out ( <td width="60%"> );
    
      // if the form has an email address, validate it first
      // so that if it fails we can show the form to fix
      var sEmail = "";
      var bSubmitted = (Request.Form.Count > 0);

      // has the form been submitted?
      if ( bSubmitted )
      {
         // get the email address from the form...
          sEmail = "" + Request.Form ( "email" );

         // validate the email address and moan if it fails
         if ( !IsValidEmail ( sEmail ) )
         {
            Out ( <h5><font color="red">" + sEmail + " <i>appears</i> to be an invalid email address - please try again!</font></h5> );
            Out ( <p><font color="red">If you disagree, please <a href="Contact.asp">contact me</a> directly.</font><p> );
            // pretend the form hasn\t been sent yet
            bSubmitted = false;
         }
      }

      // show the form if not submitted yet
      if ( !bSubmitted )
      {
         Out ( If you\re interested in hearing whenever a new article is posted, or an existing one is updated, type in your email address below and hit <b>Subscribe!</b> );
         Out ( <p>Whenever you want to stop receiving my emails, guess what? That\s right, enter your email address and hit <b>Unsubscribe</b>... );
         Out ( <p><i>Your email address will never sold to or otherwise used by any third party, just me.</i> );

         // heres the form tag. the action attribute is the name of
         // the file that will be called with the answer - in this case
         // its the same page. the method can be "post" to send the
         // form data behind the scenes or "get" to appending the
         // data to the URL in the style page.asp?data1=a&data2=b
         //
         // use post most of the time - its neater and "get" is limited
         // in the amount of data that can be sent.
         Out ( <center><form action="Subscribe.asp" method="post"> );
    
            // another table to line up the titles and inputs
            Out ( <table border="0" cellpadding="0"> );
            Out ( <tr><td align="right" valign="top"> );
               Out ( Email: );
            Out ( </td><td align="left" valign="top"> );
               // a simple text box. well reference it with the name "name"
               // and show 22 characters on the form. use the maxlength
               // attribute to set the maximum characters they can enter.
               // use value="some text" to pre-fill the input with data.
               //
               // IMPORTANT! using names that are commonly used by
               // other web sites has a big advantage to the user - IE
               // will drop down a list of previous answers, which they
               // can usually pick from rather than type in. Think about this.
               Out ( <input type="text" name="email" size="31" value=" + sEmail + "></input> );
            Out ( </td></tr> );

            Out ( <tr><td align="right" valign="top"> );
               Out ( &nbsp; );
            Out ( </td><td align="left" valign="top"> );
               // type=submit" provides a submit button to perform the
               // form action. the button says "Submit" unless you override
               // with the value attribute.
               Out ( <input type="submit" name="action" value="Subscribe"></input>&nbsp;<input type="submit" name="action" value="Unsubscribe"></input> );
            Out ( </td></tr> );

            Out ( </table> );
         Out ( </form></center> );
      }
      else
      {
         var sAction = "" + Request.Form ( "action" );

         if ( sAction == "Subscribe" )
            AddEmail ( sEmail ) ;
         else
            RemoveEmail ( sEmail );

         Out ( <p> );
      }

      Out ( Do you want to see how this form adds and removes addresses to my database? All the source code is just a click away! );
      Out ( <p><center><a href="ShowSource.asp? page=Subscribe"><img src="images/source.gif" border=0></a></center> );
      Out ( <p>In <a href="MailToList.asp">Part 2</a> see how I wrote a form to mail all my subscribers... );

   Out ( </td> );
   Out ( <td width="20%">&nbsp;</td> );
}

// ============================================
// validate email address
// ============================================
function IsValidEmail ( sEmail )
{
   // regular expression courtesy of ed.courtenay@nationwideisp.net
   // I wont even pretend that Ive read through this yet!

   if ( sEmail.search ( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0- 9]+)*\.[A-Za-z]{2,5}/ ) != -1 )
      return true;
   else
      return false;
}


// ============================================
// add email to database
// ============================================
function AddEmail ( sEmail )
{       
   // open the connection
   DBInitConnection ( );

   // first see if they are already subscribed
   var sSQL = SELECT Email FROM MailingList WHERE Email=" + sEmail + ";;

   DBGetRecords ( sSQL );

   if ( !oRecordSet.EOF )
   {
      Out ( <h5><font color="red"> + sEmail + is already subscribed to my mailing list!</font></h5> );
      return;
   }

   // this section needs more work - what should be done is that an email is
   // sent to the email address, and only added to the database when we
   // get a reply. that way we know the address is valid and the recipient
   // really wants to join the list. for now though, well add to the db now.
   sSQL = INSERT INTO MailingList (Email) VALUES (" + sEmail + ");;

   oConnection.Execute( sSQL );

   // free the connection
   DBReleaseConnection ( );

   Out ( sEmail + has been successfully subscribed to my mailing list. );
   Out ( <p>You will now receive an email whenever I write new articles, or if I make an important update to any. );

   Email ( Joined the ShawThing mailing list, sEmail, You have successfully subscribed to the mailing list at ShawThing. If you didn\t request this please reply to this email, or visit http://www.shawthing.com/subscribe.asp to unsubscribe.\n\nThank you.\n\nJames Shaw\nhttp://www.shawthing.com/ );
}


// ============================================
// remove email from database
// ============================================
function RemoveEmail ( sEmail )
{       
   // open the connection
   DBInitConnection ( );

   // first see if they are already subscribed
   var sSQL = SELECT Email FROM MailingList WHERE Email=" + sEmail + ";;

   DBGetRecords ( sSQL );

   if ( oRecordSet.EOF )
   {
      Out ( <h5><font color="red"> + sEmail + isn\t subscribed to my mailing list!</font></h5> );
      return;
   }

   // delete from the database
   sSQL = DELETE FROM MailingList WHERE Email=" + sEmail + ";;

   oConnection.Execute( sSQL );

   // free the connection
   DBReleaseConnection ( );

   Out ( sEmail + has been successfully removed from my mailing list. );
   Out ( <p>You have been sent a confirmation email, but after that you will not receive any more emails. );

   Email ( Removal from ShawThing mailing list, sEmail, You have been successfully removed from the mailing list at ShawThing. If you didn\t request this please reply to this email, or visit http://www.shawthing.com/subscribe.asp to re-subscribe.\n\nThank you.\n\nJames Shaw\nhttp://www.shawthing.com/ );
}


// ============================================
// email me!
// ============================================
function Email ( sSubject, sEmail, sMessage )
{   // send an email to the address just to confirm what just happened
   var oMail = Server.CreateObject ( "CDONTS.NewMail" );

   // setup the mail
   oMail.From = DB@shawthing.com;

   oMail.To = sEmail;
   oMail.Importance = 1;

   oMail.Subject = sSubject;
   oMail.Body = sMessage;

   // send it
   oMail.Send ( );

   // release object
   oMail = null;
}
%>
     
utils/Database.asp
<%
// globals
var oConnection;
var oRecordSet;
var sConnection;

// ============================================
// example usage:
//      DBInitConnection ( );
//
//      var sSQL = "SELECT * FROM Somewhere";
//
//      DBGetRecords ( sSQL );
//
//      ...use oRecordSet
//
//      DBReleaseRecords ( );      // optional step
//
//      DBReleaseConnection ( );
// ============================================

// ============================================
// initializes database variables for first use on page
// ============================================
function DBInitConnection ( )
{
   // dont open it again if already opened!
   if ( sConnection != undefined )
      return;
       
   // get connection object
   oConnection = Server.CreateObject( ADODB.Connection );

   // get the database connection string
   // use MapPath to make relative path into physical path
   sConnection = Provider=Microsoft.Jet.OLEDB.4.0; Data Source= + Server.MapPath ( sDBPath );

   // open the connection
   oConnection.Open( sConnection );

   // as an attempt at optimization we now open
   // the recordset here, not in DBGetRecords()
   oRecordSet = Server.CreateObject ( ADODB.Recordset );
}

// ============================================
// tidies up after DBInitConnection
// ============================================
function DBReleaseConnection ( )
{
   // dont release the connection if not connected!
   if ( sConnection == undefined )
      return;
       
   // as an attempt at optimization we now close
   // the recordset here, not in DBReleaseRecords()
   if ( oRecordSet.State != 0 )
      oRecordSet.Close();
   oRecordSet = undefined;

   oConnection.Close();
   oConnection = undefined;
    
   sConnection = undefined;
}

// ============================================
// executes the passed in SQL statement
// and returns the oRecordSet object
// ============================================
function DBGetRecords ( sSQL )
{
   // remember that this can fail if passed garbage, and hence
   // oRecordSet will already be closed
   oRecordSet = oConnection.Execute( sSQL );
}

// ============================================
// tidies up after DBGetRecords
// ============================================
function DBReleaseRecords ( )
{
   // IMPORTANT: THIS FUNCTION INTENTIONALLY BLANK
   // as an attempt at optimization we now open/close
   // the recordset with the connection, not separately
   // so all code was moved to DBReleaseConnection.
    
   // it is recommended that you still call this function as soon
   // as the recordset is finished with.
    
   // note that it is assumed by the caller that it is legal
   // to call DBReleaseConnection without calling this function
}
%>


文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·将html表单数据存储为xml格式 - 1_asp实例
·一个功能完善的专栏管理的程序->这是asp.net的第二个应用(五)_asp实例
·通过事例学习.net的webforms技术(一)_asp实例
·通过事例学习.net的webforms技术(二)_asp实例
·如何用javascript识别netscape 6 浏览器_asp技巧
·使用javascript实现邮箱快速登录的方法!!_asp技巧
·如何从数据库得到一个列表表单_asp技巧
·使用cookie来跟踪用户_asp技巧
·一个免费的简单聊天室源代码_asp实例
·stripnonnumeric函数源程序_asp实例

最新文章
·ASP基础教程:其它的ASP常用组件
·ASP基础教程:学习ASP中子程序的应用
·ASP基础教程之ASP程序对Cookie的处理
·ASP基础教程之ASP AdRotator组件的使用
·ADO初学者教程:ADO 通过GetString()加速脚本
·ASP技巧实例:几行代码解决防止表单重复提交
·ASP常见数学函数 Abs Atn Cos 等详细详解[ 来源:网页教学网 | 作者: | 时间:2007-09-12 10:57:29 | 收藏本文 ] 【大 中 小】【名称】
·ASP基础教程之ASP AdRotator 组件的使用
·ASP读sql数据时出现乱码问题的解决方法
·PHP+MYSQL实例:网站在线人数的程序代码


 
 


版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号