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!

Building sendafriendconfirm.asp

Our confirmation page is a simple piece of text letting the user know their email was sent, and then giving them a link back to the page they were originally on.


Again we've used the Bindings panel to add the Request.fname and our url to the Return to Site link.

Finishing Off

Your remaining task is to add the correct link to sendafriend.asp to your other pages. Your users will be happily letting each other know of interesting content in no time.

HTML Content

As I mentioned earlier, you can also use ASP Smart Mailer to send HTML emails. If we combine this with the Advanced HTML Editor extension, we can allow our users to send messages with their own formatting.

Open up sendafriend.asp and delete the textarea called message from the form. Insert an Advanced HTML editor element instead and give it the name message,


You'll get a warning box saying that files have been added to the ScriptLibrary directory, and not to forget to upload them to your server.

Now we have the editor, we'll restrict what formatting the user can add using the buttons in the properties panel:


We'll limit it to fontsize and some basic text formatting.

With the form altered, let's create the basic HTML for our email. You can simply copy and paste from a dreamweaver page source if you wish. Be careful of including images, as they should be to full paths (http://www.yoursite.com/imgs/logo.jpg). I used a fairly basic piece of code:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Sent by a friend from Yoursite.com</title>
    <style type="text/css">
    <!--
    body {
    background-color: #FFFFFF;
    }
    .small{
    font-size: 8pt;
    }
    -->
    </style></head>
    <body>
    </body>
    </html>

go to the Server Behaviors panel and open up the SmartMailer behavior. Insert your HTML for the email before the current content and then put the current code between the <body> tags with a bit of HTML formatting. Alter the content-type setting to HTML. This is what the content for my email looked like after formatting:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Sent by a friend from Yoursite.com</title>
    <style type="text/css">
    <!--
    body {
    background-color: #FFFFFF;
    font-family: Arial, Helvetica, sans-serif
    }
    .small{font-size: 8pt;}
    -->
    </style>
    </head>
    <body>
    <p>Your friend ##Request("name")## visisted page: ##Request("url")##</p>
     <p>They also left the following message:</p>
    ##Request("message")##
    <p class="small">This message sent via the sendafriend script at oursite.com. Report abuse of the script to: abuse@oursite.com . The sender's IP address was ##Request.ServerVariables("REMOTE_ADDR")##</p>
    </body>
    </html>

Next, we need to get rid of the linebreaks, since if we don't Smartmailer adds <br> tags at every line change, which interferes with the HTML.


Click OK and close the dialog. Now your sendafriend script sends nicely formatted HTML!

There's far more that can be achieved with the Smart Mailer extension. Don't forget that, once you own Smart Mailer, you can use it in any number of pages on any number of sites – you don't need to buy it for each site you create. Next time, we're going to take a look at sending out a newsletter to a list of subscribed users!

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