To find out where the user came from, you can look at the Referer header, although you can't rely on this always being set. For a more reliable method, embed the current URL into the request, via a CGI parameter:
<!-- On page /example/page1.html -->
<a href="/cgi-bin/tellafriend?url=/example/page1.html">
Tell a Friend!
</a>