Solved

Email page to a friend

Posted on 2004-05-03
5
778 Views
Last Modified: 2011-09-20
Hi, I want to have the facility to be able to send a page on my website to a friend (similar to the link on the left of this post).

However, I want it to be a HTML email. The formatting of the email isn't the problem. I have already done this, i just feel i am doing it the really long way round.

Basically, it is a property company and if you were on the following page  http://www.dont-click-this-link.com/prop.asp?id=7

You would see all the information for that page inc. Price, Property Name, Property Description and a Picture etc...

I want people to be able to click a EMAIL ME THIS PROPERTY button and it sends them a HTML formatted Email of exactly what they are looking at.


Here is something I have managed to get working but it is a long winded process and looks ugly and involes text boxes which i dont think are necessary!

emailpage.asp
=================
<%@ language=vbscript %>

<%
Dim intPageStatus, strStatusMessage, sName, sEmail, sSubject, sMessage, sMyMail, sInfo, sProp, sPrice, sRef, sBus
%>

<%      
if request.servervariables("CONTENT_LENGTH") > 0 then
      intPageStatus = 1 'meaning form has been submitted
      
      sName = request.Form("txtName")
      sEmail = request.Form("txtEmail")
      sSubject = "Property Enquiry..."
      sMyMail="me@mycompany.co.uk"
      sInfo = Request.Form("txtInfo")
      sProp = Request.Form("txtProp")
      sPrice = Request.Form("txtPrice")
      sRef = Request.Form("txtRef")
      sBus = Request.Form("txtBus")
      
      else
            ' continue with script
      end if

%>

<html>
<head>
<title>Contact Page</title>
<script language="JavaScript" type="text/JavaScript">
<!--

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include file="dbconnect.asp" -->

<%
Dim rs__MMColParam
rs__MMColParam = "1"
If (Request.QueryString("id") <> "") Then
  rs__MMColParam = Request.QueryString("id")
End If
%>

<%
Dim rs
Dim rs_numRows

Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_dbconn_STRING
rs.Source = "SELECT *  FROM properties WHERE id = " + Replace(rs__MMColParam, "'", "''") + ""
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()

rs_numRows = 0
%>
</head>
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0" height="100%">
<tr>
<td><table width="770" border="0" cellpadding="0" cellspacing="0" height="100%">
    <tr>
   
    <tr>
      <td width="770" height="100%" valign="top" bgcolor=""><table width="770" border="0" cellpadding="0" cellspacing="0">
               <tr>
                 
                <td valign="top">
<%
Select Case intPageStatus
      Case 0%>

      <form action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="post" name="contact" id="contact">
  <table width="75%" border="0" align="center" cellpadding="4" cellspacing="2">
    <tr valign="top">
      <td>        <center>
        Please fill in the details below and an email will be sent to us.<br>
        Once received, we will get back to you as soon as possible.
      </center></td>
    </tr>
    <tr valign="top">
      <td>
            <table width="422" border="0" align="center" cellpadding="0" cellspacing="0" background="images/content-bg.jpg">
          <tr>
            <td><div>Property Details </div>
                <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td><table width="400"  border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <th colspan="2"><input name="txtProp" type="text" id="txtProp" value="<%=(rs.Fields.Item("prop").Value)%>" size="50"></th>
                        </tr>
                        <tr>
                          <td width="180"><img src="images/65.jpg" title="Image" name="underoffer" width="180" height="135" border="0" id="underoffer" /></td>
                          <td><ul>
                              <li>Property Ref:
                                  <input name="txtRef" type="text" id="txtRef" value="<%=(rs.Fields.Item("reference").Value)%>" />
                              </li>
                              <li>Business Type:
                               
                                <input name="txtBus" type="text" id="txtBus" value="<%=(rs.Fields.Item("bustype").Value)%>">
                                </li>
                              <li>Price: &pound;
                                <input name="txtPrice" type="text" id="txtPrice" value="<%= FormatCurrency((rs.Fields.Item("price").Value), -1, -2, -2, -2) %>">
                              </li>
                          </ul></td>
                        </tr>
                        <tr>
                          <td colspan="2"><p>&nbsp;
                            <textarea name="txtInfo" cols="65" rows="10" id="txtInfo"><%=(rs.Fields.Item("info").Value)%></textarea>
                          </p>
                              <p> If you are interested in this property please contact us quoting the above reference<br />
                            </p></td>
                        </tr>
                    </table></td>
                  </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="422"  border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="423">If you are thinking of selling your property then contact the office for a <br />
            Free No Obligation Valuation</td>
                </tr>
            </table></td>
          </tr>
        </table>
            Email:<br>          <input name="txtEmail" type="text" id="txtEmail" size="30">
</td>
    </tr>
    <tr valign="top">
      <td>        <center>
        <input name="Submit" type="submit" onClick="MM_validateForm('txtName','','R','txtTel','','R','txtEmail','','RisEmail','txtMessage','','R');return document.MM_returnValue" value="Submit">
      </center></td>
    </tr>
  </table>
      </form>

      <%Case 1

Set MyCDONTSMail2 = CreateObject("CDONTS.NewMail")
HTML = HTML & "<HTML>"
HTML = HTML & "<HEAD><meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1""></HEAD>"
HTML = HTML & "<BODY>"
HTML = HTML & "<img height=112 alt="""" src=""http://www.website.co.uk/images/logo.jpg"" width=105 border=0>"
HTML = HTML & "<p><FONT face=Arial color=#333333 size=4>Thank you for your enquiry on the Website. A Member of staff will be contact you as soon as possible...</FONT></p>"
HTML = HTML & "<p><FONT face=Arial color=#333333 size=3>Below is what you submitted:</FONT></p>"
HTML = HTML & "<table width=""500"" border=""0"" cellspacing=""0"" cellpadding=""0"">"
HTML = HTML & "<tr>"
HTML = HTML & "<td width=""80""><strong><font face=Arial, Helvetica, sans-serif color=#333333 size=2>Bus Type</font></strong></td>"
HTML = HTML & "<td width=""356""><font color=""#0000FF"" size=""2"" face=""Arial, Helvetica, sans-serif"">" & sBus & "</font></td>"
HTML = HTML & "</tr>"
HTML = HTML & "<tr>"
HTML = HTML & "<td><font size=""2"" face=""Arial, Helvetica, sans-serif""><strong>Prop Info</strong></font></td>"
HTML = HTML & "<td><font color=""#0000FF"" size=""2"" face=""Arial, Helvetica, sans-serif"">" & sInfo & "</font></td>"
HTML = HTML & "</tr>"
HTML = HTML & "<tr>"
HTML = HTML & "<td><font size=""2"" face=""Arial, Helvetica, sans-serif""><strong>Prop Name</strong></font></td>"
HTML = HTML & "<td><font color=""#0000FF"" size=""2"" face=""Arial, Helvetica, sans-serif"">" & sProp & "</font></td>"
HTML = HTML & "</tr>"
HTML = HTML & "<tr>"
HTML = HTML & "<td><font size=""2"" face=""Arial, Helvetica, sans-serif""><strong>Price</strong></font></td>"
HTML = HTML & "<td><font color=""#0000FF"" size=""2"" face=""Arial, Helvetica, sans-serif"">" & sPrice & "</font></td>"
HTML = HTML & "</tr>"
HTML = HTML & "<tr>"
HTML = HTML & "<td><font size=""2"" face=""Arial, Helvetica, sans-serif""><strong>Prop Ref</strong></font></td>"
HTML = HTML & "<td><font color=""#0000FF"" size=""2"" face=""Arial, Helvetica, sans-serif"">" & sRef & "</font></td>"
HTML = HTML & "</tr>"
HTML = HTML & "</table>"
HTML = HTML & "</BODY></HTML>"
    MyCDONTSMail2.From= sEmail
    MyCDONTSMail2.To= sMyMail
    MyCDONTSMail2.CC= sEmail
    MyCDONTSMail2.Subject= sSubject
    MyCDONTSMail2.BodyFormat=0
    MyCDONTSMail2.MailFormat=0
    MyCDONTSMail2.Body=HTML
    MyCDONTSMail2.Send
    set MyCDONTSMail2= nothing
Response.Write ("<p><class=""std"">Dear " & sName & ",&nbsp; Your enquiry has been sent...</font></p>")
Response.Write ("<p><class=""std"">A copy has also been sent to <strong>" & SEmail & "</strong>&nbsp; for your records.</font></p>")
Response.Write ("<p><class=""std""><a href=""index.asp"">Please click here to continue...</a></font></p>")
      Case else
      ' some error....
End Select
%>
                </td>
               </tr>
           </table>
          </td>
    </tr>
</table>


</td>
<td width="100%">&nbsp;</td>
</tr>
</table>
</body>
</html>
0
Comment
Question by:JamesMonaghan
  • 3
  • 2
5 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 10977751
Use XMLHTTP:

0
 
LVL 31

Expert Comment

by:alorentz
ID: 10977773
Example:

DIM ObjXMLHTTP, StrValue, URL


URL = "http://www.dont-click-this-link.com/prop.asp?id=7"

Set ObjXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
ObjXMLHTTP.Open "GET", URL, false
ObjXMLHTTP.Send
StrValue = ObjXMLHTTP.ResponseText
Set ObjXMLHTTP = nothing

Set objCDOMail = Server.CreateObject("CDO.Message")
   

objCDOMail.Sender = "from email"
objCDOMail.To = "to email"
objCDOMail.Subject = "From a frien"
objCDOMail.HTMLBody = strvalue  '<-------------this contains the page to send


objCDOMail.Send

Set objCDOMail = Nothing
%>
0
 

Author Comment

by:JamesMonaghan
ID: 10978067
That is very helpful, just a few more things to make it perfect:

 - If i am on that particular page (prop.asp?id=7) what code would i need to use on the Submit button (send to a friend) because i want people to be able to click this button on any property and the code above only relates to that particular property.

Lets assume i create a page called sendtofriend.asp with the code above, how do i 'post' the parameters to sendtofriend.asp

- How would i add a text box to the above for the person to put their email address?

Many Thanks for your speedy response...
0
 
LVL 31

Accepted Solution

by:
alorentz earned 250 total points
ID: 10978187
You just post the the form to itself on that page....then when they click Send to friend button, send the email..

on the prop.asp page'''''''''

'add this to your existing code

<form action="" method=post>
Send to friend <BR>
Email: <input type=text name=email>
<input type=submit name=submit value="Send to Friend">
</form>
<%
if request("submit") <> "" then
DIM ObjXMLHTTP, StrValue, URL


URL = request.servervariables("HTTP_Referer")

Set ObjXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
ObjXMLHTTP.Open "GET", URL, false
ObjXMLHTTP.Send
StrValue = ObjXMLHTTP.ResponseText
Set ObjXMLHTTP = nothing

Set objCDOMail = Server.CreateObject("CDO.Message")
   

objCDOMail.Sender = "agent@yourdomain.com"
objCDOMail.To = request("email")
objCDOMail.Subject = "From a friend"
objCDOMail.HTMLBody = strvalue  '<-------------this contains the page to send


objCDOMail.Send

Set objCDOMail = Nothing
end if
%>


That should be enough information for this question...
0
 

Author Comment

by:JamesMonaghan
ID: 10978327
Brilliant, Thank you
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now