Free! A send-a-friend application with ASP Smart Mailer Support

The great thing with DMXzone's extensions is that they make the tedious work of developing advanced functions easy, allowing you to concentrate on the exciting aspects of the job.

In this free tutorial, Matt Machell shows how to use the DMXzone ASP Smart Mailer to add a "send-a-friend" link to your web pages, allowing a user to alert a friend to an interesting page by clicking a link, entering an email address and the DMXzone extension and your web server do the rest. It'll have you up and running this functionality on any page, on any number of sites, in practically no time at all!

A send-a-friend application with ASP Smart Mailer

Every site likes more visitors. One of the ways that big sites do this is using a simple form that allows people to send their friends a quick email about your site. In this tutorial we're going to build a quick and easy, but fully functional version of this application using the DMXZone ASP Smart Mailer Extension.

What you'll need

You'll need a web server that supports ASP. The server will also need one of the many mailing programs supported by ASP installed on it. This is the default for most hosting companies, but may not be the case on your own test rig.

ASP Smart Mailer will work with CDO, CDONTS, ASPMail, ASPEmail and Jmail. You'll also need Dreamweaver MX 2004 (it works with MX too) and the DMXZone ASP Smart Mailer extension installed.

Starting off

As with any dynamic page, you'll need to define a site before you can use server behaviors. I'll assume you can set one up, but if not then why not check out Molly Holzschlag's  tutorial on the subject. You'll need to use the ASP VBScript server model.

First off we'll need 3 files:

·       sendafriend.asp

·       sendafriendconfirm.asp

·       sendafriendstyles.css

What the application does

When a user visits our site, they view our pages, and on each of them is a link to sendafriend.asp. In addition to the basic link, the link also contains an url parameter which is the page's address. So, for example, on a page called myfaq.html the link would be: sendafriend.asp?url=http://www.mysite.com/myfaq.html.

Note that we'll need to include the entire url with the full path, as a relative url would be no use to somebody receiving the link via email.

When the browser clicks on the link, they are taken to our sendafriend.asp page. They fill in their name and email, and their friend's details, and a brief message, and then they click submit. Our server does some work and creates an email based on the user input and sends the mail.

The user is then forwarded to a confirmation page, which contains a link back to the original page they were browsing. Their friend receives a message with the URL in question.

Creating sendafriend.css

This CSS file contains the basic formatting information for our application. Again, I advise developing the logic first with minimal styling, and then enhancing the pages to your required standard of breathtaking aesthetic loveliness once you've got the nuts and bolts all working.

So this CSS is deliberately nothing fancy, just some basic font styles for the whole page, an id called #message that will be used to highlight the default message and some form styling.

    body {
          font-family: Arial, Helvetica, sans-serif;
          font-size: smaller;
    }
    #message {
          border: 1px solid #000000;
          padding: 4px;
    }
    form {
          border: 1px solid #003399;
          padding: 4px;
          background-color: #CAF2FF;
    }

Save and close the file.

Matt Machell

Matt MachellA man of many talents, Matt has been a web designer, technical editor, and jewellery picker. He is currently on contract for the Birmingham City University, producing pages for research centres.

He has tech-edited a dozen books on web design and development for glasshaus, Apress and Sitepoint.

He likes music with loud guitars and games with obscure rules.

His website can be found at: http://www.eclecticdreams.com

He lives in Birmingham with his girlfriend, Frances, and a horde of spider plants.

See All Postings From Matt Machell >>