NewsRhzhi | 先创资讯 | 旧版入口
rhzhi.net
网站首页 | NewsRhzhi | 先创资讯 | 操作系统 | 工具软件 | 办公软件 | 网站设计 | 组网专栏 | 平面设计 | 多 媒 体 | 程序开发 | 硬件资料 | 聊天软件
您现在的位置: 先创网 >> 程序开发 >> ASP >> 文章正文
一个免费的邮件列表源程序(三)
itbulo.com
2005-6-28文/未知
    

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>' );

         // here's the form tag. the action attribute is the name of
         // the file that will be called with the answer - in this case
         // it's 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 - it's 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. we'll 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 won't even pretend that I've 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, we'll 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

 

[1] [2] 下一页

打印此页 投稿与建议 返回顶部
栏 目 索 引
软件应用 SOFTWARE
Win XP | NT/2003
Win2000 | DOS/Win9x
PowerPoint | Office
Excel | Word
网络软件 | 实用软件
媒体软件 | 系统软件
常用软件 | 办公软件
聊天软件 | 网络安全
新软试用 | Vista
设计在线 DESIGN
Dreamweaver | 3DMax
Photoshop | Flash
平面设计 | 网页设计
多 媒 体 | 精品画廊
精彩专区 SPECIAL
Q Q 专区 | 热门专题
组网玩网 | 程序开发
应用集锦 |

没有任何图片文章
相关文章
关于我们 - 联系方式 - 合作伙伴 - 网站大事记 - 网站地图 - 我要投稿
Copyright ©1997-2008 先创网 All Rights Reserved.
先创科技 版权所有