Hi all, im trying to make a script which sends the link of the page to a specified email address. I have made it work by using a script from an external file, but when i call up the server variable request url, ht gets the wrong one, so i put the script in the same page as the page that needs to be called up in the email. The script is kinda complicated (for me - i am self tought) and could sombody tell me what im doing wrong? here it is:

<%
Response.Buffer = True
'Dimension variables
Dim strBody    'Holds the body of the e-mail
Dim objJMail    'Holds the mail server object
Dim strMyEmailAddress   'Holds your e-mail address
Dim strSMTPServerAddress 'Holds the SMTP Server address
Dim strCCEmailAddress  'Holds any carbon copy e-mail addresses if you want to send carbon copies of the e-mail
Dim strBCCEmailAddress  'Holds any blind copy e-mail addresses if you wish to send blind copies of the e-mail
Dim strReturnEmailAddress 'Holds the return e-mail address of the user
 
'----------------- Place your e-mail address in the following sting ---------------------------------
strMyEmailAddress = request.form("femail")
'---------- Place the address of the SMTP server you are using in the following sting ---------------
strSMTPServerAddress = "smtp.ntlworld.com"
'-------------------- Place Carbon Copy e-mail address in the following sting ------------------------
strCCEmailAddress = request.form("yemail") 'Use this string only if you want to send the carbon copies of the e-mail
'-------------------- Place Blind Copy e-mail address in the following sting -------------------------
strBCCEmailAddress = "" 'Use this string only if you want to send the blind copies of the e-mail
'-----------------------------------------------------------------------------------------------------
 
'Read in the users e-mail address
strReturnEmailAddress = Request.Form("yemail")
 
'Initialse strBody string with the body of the e-mail
strBody = request.form("yname") & "<h2> has seen a picture they liked, and thought you would like to!</h2>" & <br> "<u>Below is a comment that they wrote for you:</u>" <br> & "<b><u>Message:</u></b>"  & request.form("message")<br> & "<[URL]http://www.ThemePics.co.uk/[/URL]" & Request.ServerVariables("URL")
'Check to see if the user has entered an e-mail address and that it is a valid address otherwise set the e-mail address to your own otherwise the e-mail will be rejected
If Len(strReturnEmailAddress) < 5 OR NOT Instr(1, strReturnEmailAddress, " ") = 0 OR InStr(1, strReturnEmailAddress, "@", 1) < 2 OR InStrRev(strReturnEmailAddress, ".") < InStr(1, strReturnEmailAddress, "@", 1) Then
 
 'Set the return e-mail address to your own
 strReturnEmailAddress = strMyEmailAddress
End If 
'Send the e-mail
'Create the e-mail server object
Set objJMail = Server.CreateObject("JMail.SMTPMail")
'Out going SMTP mail server address
objJMail.ServerAddress = strSMTPServerAddress
'Senders email address
objJMail.Sender = strReturnEmailAddress
'Senders name
objJMail.SenderName = Request.Form("yName")
'Who the email is sent to
objJMail.AddRecipient strMyEmailAddress
'Who the carbon copies are sent to
objJMail.AddRecipientCC strCCEmailAddress
'Who the blind copies are sent to
objJMail.AddRecipientBCC strBCCEmailAddress
'Set the subject of the e-mail
objJMail.Subject = request.form("yname")&" has invited you to view this picture!"
 
'Set the main body of the e-mail (HTML format)
objJMail.HTMLBody = strBody
'Set the main body of the e-mail (Plain Text format)
'objJMail.Body = strBody
'Importance of the e-mail ( 1 - highest priority, 3 - normal, 5 - lowest)
objJMail.Priority = 3 
'Send the e-mail
objJMail.Execute
 
'Close the server object
Set objJMail = Nothing
%>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks guys :mrgreen:

Recommended Answers

All 3 Replies

Most probably you are getting the URL of the page where this script placed! If yes so, You can use the hidden field in the form to store the URL then use the into asp script

you can add this line in html form,

<input name="urlHolder" type="hidden" id="urlHolder" value="<%=Request.ServerVariables("URL")%>">

and this in asp script

Dim urlHolder 'Holds The URL of the Page Where the HTML form is
urlHolder = request.form("urlHolder")
strBody = request.form("yname") 
strBody =  strBody & "<h2> has seen a picture they liked, and thought you would like to!</h2>"
strBody =  strBody & "<br><u>Below is a comment that they wrote for you:</u><br>" 
strBody =  strBody & "<b><u>Message:</u></b>"  & request.form("message") 
strBody =  strBody & "<br><a href='http://www.ThemePics.co.uk/" & urlHolder &"'>" 
strBody =  strBody & "http://www.ThemePics.co.uk/" & urlHolder & "</a>"

Example : http://www.katarey.com/forHelp/2a.asp
I hope this will helpful for you

Best Regards,
Rahul

and you can also use this :

request.servervariables("HTTP_REFERER")
Instead of 
Request.ServerVariables("URL")

Complete Code :

<%
Response.Buffer = True
'Dimension variables
Dim strBody    'Holds the body of the e-mail
Dim objJMail    'Holds the mail server object
Dim strMyEmailAddress   'Holds your e-mail address
Dim strSMTPServerAddress 'Holds the SMTP Server address
Dim strCCEmailAddress  'Holds any carbon copy e-mail addresses if you want to send carbon copies of the e-mail
Dim strBCCEmailAddress  'Holds any blind copy e-mail addresses if you wish to send blind copies of the e-mail
Dim strReturnEmailAddress 'Holds the return e-mail address of the user
 
'----------------- Place your e-mail address in the following sting ---------------------------------
strMyEmailAddress = request.form("femail")
'---------- Place the address of the SMTP server you are using in the following sting ---------------
strSMTPServerAddress = "smtp.ntlworld.com"
'-------------------- Place Carbon Copy e-mail address in the following sting ------------------------
strCCEmailAddress = request.form("yemail") 'Use this string only if you want to send the carbon copies of the e-mail
'-------------------- Place Blind Copy e-mail address in the following sting -------------------------
strBCCEmailAddress = "" 'Use this string only if you want to send the blind copies of the e-mail
'-----------------------------------------------------------------------------------------------------
 
'Read in the users e-mail address
strReturnEmailAddress = Request.Form("yemail")
 
'Initialse strBody string with the body of the e-mail
strBody = request.form("yname") 
strBody =  strBody & "<h2> has seen a picture they liked, and thought you would like to!</h2>"
strBody =  strBody & "<br><u>Below is a comment that they wrote for you:</u><br>" 
strBody =  strBody & "<b><u>Message:</u></b>"  & request.form("message") 
strBody =  strBody & "<br><a href='" & request.servervariables("HTTP_REFERER") &"'>" 
strBody =  strBody & request.servervariables("HTTP_REFERER") & "</a>"

'Check to see if the user has entered an e-mail address and that it is a valid address otherwise set the e-mail address to your own otherwise the e-mail will be rejected
If Len(strReturnEmailAddress) < 5 OR NOT Instr(1, strReturnEmailAddress, " ") = 0 OR InStr(1, strReturnEmailAddress, "@", 1) < 2 OR InStrRev(strReturnEmailAddress, ".") < InStr(1, strReturnEmailAddress, "@", 1) Then
 
 'Set the return e-mail address to your own
 strReturnEmailAddress = strMyEmailAddress
End If 
'Send the e-mail
'Create the e-mail server object
Set objJMail = Server.CreateObject("JMail.SMTPMail")
'Out going SMTP mail server address
objJMail.ServerAddress = strSMTPServerAddress
'Senders email address
objJMail.Sender = strReturnEmailAddress
'Senders name
objJMail.SenderName = Request.Form("yName")
'Who the email is sent to
objJMail.AddRecipient strMyEmailAddress
'Who the carbon copies are sent to
objJMail.AddRecipientCC strCCEmailAddress
'Who the blind copies are sent to
objJMail.AddRecipientBCC strBCCEmailAddress
'Set the subject of the e-mail
objJMail.Subject = request.form("yname")&" has invited you to view this picture!"
 
'Set the main body of the e-mail (HTML format)
objJMail.HTMLBody = strBody
'Set the main body of the e-mail (Plain Text format)
'objJMail.Body = strBody
'Importance of the e-mail ( 1 - highest priority, 3 - normal, 5 - lowest)
objJMail.Priority = 3 
'Send the e-mail
objJMail.Execute
 
'Close the server object
Set objJMail = Nothing
%>

in this Example you don’t need to change in your html form

tnx for all the help. works perfectly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.