Dreamweaver UltraDev Cookbook

Email Confirmation Example

Hiran de Silva
July 2000

Who this tutorial is for

How does it work?

How about stuff all the data in the New User Registration form into Session Variables, then pick them up on a Confirmation page and send an email from it?

It's convenient, but unfortuntely a little limited. We're going to use a better approach.

We will stuff just the UserID into a Session Variable. Then we get the next page, the Confirmation page, to find the newly created record in the database using the UserID passed by the Session Variable. Then we will get the page to send an email from the data in the record it has found.

This approach will be a lot more useful in heaps of other applications, such as sending email notification of events and reminders to multiple selected members (no spam please! Be serious).

Try the demo. In a later tutorial we will explore how to compose customised content. Let's learn the basics first.

Steps

1 Create a Session Variable on Registration Page - a little code
2 Create a Recordset on Confirmation Page - UltraDev will do this for you
3 Test that the Recordset gives us what we want
4 Add the code for sending email (eg. JMail, CDONTS)

You will need to find out from your web host which mail programs are available to you. The code in this demo and example is JMail. The code for CDONTS is similar (check back for an example).

1 Create a Session Variable on the Registration Page

First we need to re-visit the newregister.asp page and insert just one line of code in it.

This bit of code stuffs the Session Variable svUserID with the data collected on the form. But where do we put it? Logic would say it goes after the Insert Record code that UltraDev wrote for us, wright? Wrong!

Dear reader, this code needs to occur before the Insert Record code if it is to do its job properly.

The reason is not too obvious but here it is ... the UltraDev's Insert Record code reloads the page. So if you want to catch the data in the form you need to do that before the reloaded page clears them. (Glad you asked?)

I suggest you place the code immediately below the @Language=VBScript bit.

2 Create a Recordset on the Confirmation Page

So now we have a Session Variable that holds the UserID and you know that we can pick this up on the Confirmation page (or indeed any page on the site during this visitor's visit). We will create a recordset called rsThisUser just as we did in Lessons 1 and 3. The only difference is - the run-time Value of strUserID will now be the value we stuffed into the Session Variable svUserID.

This should give us a recordset with just one record - the one we want - the record for the new user. rsThisUser!

3 Test what we have done so far

Before moving on to Step 4 we can save ourselves a lot of frustration by checking that we're on the right track so far.

So, go ahead and make the Confirmation page display the Session Variable svUserID and also make it display the fields from the one-record recordset rsThisUser. You've seen this in the demo.

(How do I do that, Hiran? How about using the Data Binding inspector?)

4 Add the code for sending an email

Have you done Step 3?

We'll start by putting the new user's Email Address into a variable strRecipient. It's good practice to use variables even though its sometimes not entirely necessary. So let's do that.

Then add the following code (for JMail), replacing the relevant text to suit your purpose and your host's setup. For example address of your local SMTP server - you'll need to get this info from your web host. If your server runs CDONTS go here for the alternative code (TBA).

Now try it out.
If it didn't work first time remember that if it worked for you up to Step 3 you're 90% there.

Vroom! Vroom!

Next time we'll look at:

How to compose and send custom emails from data in a database, such as forgotten passwords.
How to authenticate email address via an authentication link back.

Troubleshooting Tips
Write a Review of this Tutorial
Read Reviews

Please send comments to Hiran de Silva.

Home