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!

Creating sendafriend.asp

Our basic page looks as follows:


The layout comes from our stylesheet, so start by adding that to the page. You can do this with the attach stylesheet button in the CSS Styles pane of the design panel (highlighted in red on the screenshot below).


Once the stylesheet is added you just need to put the relevant paragraphs and form fields in place. The form fields are named message, name, email, fname and femail. The paragraphs containing the sample message are wrapped in a div with id attribute of message.

    <div id="message">
      <p> Your friend <em>yourname</em> visited page: Page</p>
      <p>They also left the following message:</p>
    </div>

Right, now it's time to start adding our dynamic data. Go to the Bindings pane of the application panel. We're going to add a number of request variables, using + > Request Variable:


Most of these are just simple request variables (message, email, femail, fname and url). The last is a server variable called REMOTE_ADDR. This is a piece of information that the server has received from the user's browser, telling it where the request came from as an IP address. We'll use this later in our precautions against abuse of the script.

Now that the bindings are added, go back to the main page and add a hidden field to the form. This field should be named url and have a dynamic value from our Request variable url. Why do this? Well, the url the user is interested in gets sent to the page first from the link they click on.

//6However, when the submit button on the next page is clicked, we're requesting a new URL, so the URL that you want to send to your friend will be lost, so we need to resend the url as part of the form. (Of course, if you've only got plans to use this for one page, you can hard-code the URL into the form, but good practice is to make the forms as re-usable as possible.)

Again on the main page, we're going to add the url after our "your friend visited the page:" text.  In the bindings panel, we'll select the url request variable and use the insert button at the bottom of the Bindings panel (shown in the screenshot below). This is so the user can check the url is correct before proceeding.


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 >>