|
// open the connection DBInitConnection ( );
// get the emails addresses var sSQL = 'SELECT Email FROM MailingList;';
DBGetRecords ( sSQL );
var sEmailList = ""; var sSep = "";
while ( !oRecordSet.EOF ) { sEmailList += sSep + oRecordSet ( 0 );
sSep = ";";
oRecordSet.MoveNext ( ); }
// free the connection DBReleaseConnection ( );
Email ( 'It\'s a ShawThing - what\'s new?', sEmailList, sMessage );
Out ( '<p>Email sent successfully.<p>' ); }
Out ( 'Want to see how this form to mail the subscribers was done? Click below to get all the source code!' ); Out ( '<p><center><a href="ShowSource.asp? page=MailToList"><img src="images/source.gif" border=0></a></center>' );
Out ( '</td>' ); Out ( '<td width="20%"> </td>' ); }
// ============================================ // 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 = oMail.To = 'MailingList@shawthing.com';
oMail.Bcc = 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 ( ) { // don't 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 ( )
|