Solved

Send mailform from an email

Posted on 2004-03-23
4
154 Views
Last Modified: 2010-04-06
G'day there,

I have successful mail forms on my website that send from web form to email, however I would like to send a HTML email to my mailing list asking them a question in a HTML form.

I just want all those users to select either Yes/No and press the submit button from their email which will then send the mailform to my email address.

Is this possible?

I know I would need to point the 'GET' in the HTML email to a formmail on my webserver which isn't a problem. But this still doesn't work. I guess because of the 'referrers' option in the scripts available out there. Because the form is not on a webserver and only in an email I cannot put it into the referrers.

Hopefully someone can help

Thanks
Chad
0
Comment
Question by:The-Chad
  • 2
4 Comments
 
LVL 4

Expert Comment

by:AsbjornG
ID: 10664303
Hi Chad,

Could you please show me the code for your formmail script, and the vital parts of your HTML form?

In order to make this work you would probably have to open your GET request in a new browser window using javascript, but I'd like to make sure it's not the referer as you say before I dig up the code.

Cheers,

Asbjorn
0
 
LVL 1

Expert Comment

by:j_chakraverty
ID: 10672573
referrer can be a problem at times but not because of bieng in the email.
emails in most cases use explorer if you are using a windows system and outlook for the email u shall see that referar is a intenet explorer

But many third part softwares switch of the referrer to protect your personal data.
Norton Fire wall is one that i know of it converts referr to weferer which is again a encrypted

as it s not the problem of identity of the browser so the javascript to pop up a new window may not work if my hunch is correct about your problem.

 for an html email just referrer to get data but dont rely on it ever cos all these dat acan be faked too. and any way many people like to block that data which is fair on their part

HOPE IT HELPS any help post here
0
 
LVL 1

Author Comment

by:The-Chad
ID: 10673190
Here is the formmail code:


<%@ Language = vbscript%>
<%option explicit %>
<%server.scripttimeout = 600 %>
'----------------------------------------------------------------------------------------------------
'declare variables
'----------------------------------------------------------------------------------------------------
Dim strFrom, strTo, strSubject, strBody
Dim objMessage, objConfig, strServer, intPort
Dim recipient, redirect, subject, realname, email, required, strEmail1, strEmail2
Dim referer, url, url_verified, icounter, query, iloop, query2, query3, i, agree, validation, error0, error0ok

'############################## CONFIGURATION VARIABLES ####################################

'These are the only lines you will need to change
'----------------------------------------------------------------------------------------------------
strServer = "mymailserver.com" 'set which smtp server will be used to send the email. enter ip address or domain name. eg: "xxx.xxx.xxx.xxx" or "smtp.your-domain.com"
intPort = 25 'set the smtp port to be used when sending mail (by default port 25 is used)
'Referrer's Array is defined here. Enter the valid domains which may use this script.
url = Array("mydomain.com")'Set which urls that will be accepted. http://xxxxx/
      'Seperate multiple domains by commas
      'eg: url= Array("www.your-domain.com","your-domain.com","www.my-domain.com")
      'computer names can be used instead of domains if this script is being run locally
      'eg: url = Array("computername")

'######################################### IMPORTANT NOTICE #########################################
'IMPORTANT: do not modify anything below this line unless you know what you are doing!!
'######################################### IMPORTANT NOTICE #########################################
      
'----------------------------------------------------------------------------------------------------
'information type and CDOSYS constants
'----------------------------------------------------------------------------------------------------
%>
<!--METADATA TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library" -->
<%
'----------------------------------------------------------------------------------------------------
'retrieved default fields
'----------------------------------------------------------------------------------------------------
recipient = request("recipient")
redirect = request("redirect")
subject = request("subject")
required = request("required")
if required = "" then
      required = "recipient,subject,redirect"
else
      required = "recipient,subject,redirect," & required
end if

'----------------------------------------------------------------------------------------------------
'verify the referer
'----------------------------------------------------------------------------------------------------
referer = request.ServerVariables("HTTP_REFERER")
referer = split(referer,"/")
url_verified = "no"
for icounter = Lbound(url) to Ubound(url) '
      if referer(2) = url(icounter) then
            url_verified = "yes"
      end if
next
if not url_verified = "yes" then
      response.write("The url specified is invalid!")
      response.End
end if

'----------------------------------------------------------------------------------------------------
'verify the recipient(not tested)
'----------------------------------------------------------------------------------------------------
'trimed_referer = split(referer(2),".")'
'response.write recipient & "<br>" & referer(2) & "=" & trimed_referer(0) & "<br>"
'if trimed_referer(0) = "www" then
'      if InStr(1,recipient,trimed_referer(1),1) = 0 then
'            response.write "recipient don't match the referer"
'            response.end
'      end if
'else
'      if InStr(1,recipient,trimed_referer(0),1) = 0 then
'            response.write "recipient don't match the referer"
'            response.end
'      end if
'end if

'----------------------------------------------------------------------------------------------------
'retrieve form contents and create email fields
'----------------------------------------------------------------------------------------------------
query = Request.ServerVariables("QUERY_STRING")
query = split(query,"&")
query3 = split(required,",")
      For iLoop = Lbound(query) to UBound(query)
            query2 = split(query(iloop),"=")
      
'----------------------------------------------------------------------------------------------------
'form validation, checks required fields are not null
'----------------------------------------------------------------------------------------------------
            for i = LBound(query3) to UBound(query3)
                  if query3(i) = query2(0) then
                        if query2(1) = "" then
                              response.write ("you must enter a valid ") & query2(0)
                              response.end
                        end if
                  end if
                  
                  'if query2(0) = "agree" then
                        'if query2(1) <> "on" or query2(1) = "" then
                        '      response.write("You must agree to terms and conditions to enable Formmailv1.3 to execute!")
                        'response.end
                        'end if
                  'end if
                  
'----------------------------------------------------------------------------------------------------
'form validation, checks a valid email address has been specified
'----------------------------------------------------------------------------------------------------                  
                  if query2(0) = "email" then
                        trim(query2(0))
                        if len(query2(1))<8 then
                              response.Write("You must specify a valid ") & query2(0)
                              response.end
                        end if
                        if instr(query2(1),"@")=0 and instr(query2(1),".")=0 then
                              response.write query2(1)
                              response.Write("You must specify a valid ") & query2(0)
                              response.end
                        end if
                        strEmail1 = split(query2(1),"@")
                        if len(strEmail1(1))<3 then
                              response.Write("You must specify a valid ") & query2(0)
                              response.end
                        end if
                        strEmail2 = split(strEmail1(1),".")
                        if len(strEmail2(0))<3 then
                              response.Write("You must specify a valid ") & query2(0)
                              response.end
                        end if
                        if len(strEmail2(1))<2 then
                              response.Write("You must specify a valid ") & query2(0)
                              response.end
                        end if
                  end if

'----------------------------------------------------------------------------------------------------
'form validation, checks terms and conditions checkbox has been ticked
'----------------------------------------------------------------------------------------------------
                  
            Next
            if not query2(0) = "recipient" and not query2(0) = "redirect" and not query2(0) = "subject" and not query2(0) = "realname" and not query2(0) = "email" and not query2(0) = "required" and not query2(0) = "agree" then
                  strBody = strBody & vbnewline & vbnewline & query2(0) &": " & query2(1)
            end if
      Next
if email = "" then
      email = "formmail@" & referer(2)
end if
'----------------------------------------------------------------------------------------------------
'replaces any special characters parsed through the query string
'----------------------------------------------------------------------------------------------------
strbody = replace(strbody, "+"," ")
strbody = replace(strbody, "%26%238364%3B","€")
strbody = replace(strbody, "%A1","¡")
strbody = replace(strbody, "%A3","£")
strbody = replace(strbody, "%A8","¨")
strbody = replace(strbody, "%AA","ª")
strbody = replace(strbody, "%AC","¬")
strbody = replace(strbody, "%B4","´")
strbody = replace(strbody, "%B7","·")
strbody = replace(strbody, "%BA","º")
strbody = replace(strbody, "%BF","¿")
strbody = replace(strbody, "%C7","Ç")
strbody = replace(strbody, "%E7","ç")
strbody = replace(strbody, "%0D%0A",vbnewline)
strbody = replace(strbody, "%21","!")
strbody = replace(strbody, "%23","#")
strbody = replace(strbody, "%24","$")
strbody = replace(strbody, "%25","%")
strbody = replace(strbody, "%26","&")
strbody = replace(strbody, "%27","'")
strbody = replace(strbody, "%28","(")
strbody = replace(strbody, "%29",")")
strbody = replace(strbody, "%2B","+")
strbody = replace(strbody, "%2C",",")
strbody = replace(strbody, "%2D","-")
strbody = replace(strbody, "%2E",".")
strbody = replace(strbody, "%2F","/")
strbody = replace(strbody, "%3A",":")
strbody = replace(strbody, "%3B",";")
strbody = replace(strbody, "%3C","<")
strbody = replace(strbody, "%3D","=")
strbody = replace(strbody, "%3E",">")
strbody = replace(strbody, "%3F","?")
strbody = replace(strbody, "%5B","[")
strbody = replace(strbody, "%5C","\")
strbody = replace(strbody, "%5D","]")
strbody = replace(strbody, "%5E","^")
strbody = replace(strbody, "%5F","_")
strbody = replace(strbody, "%60","`")
strbody = replace(strbody, "%7B","{")
strbody = replace(strbody, "%7C","|")
strbody = replace(strbody, "%7D","}")
strbody = replace(strbody, "%7E","~")

'----------------------------------------------------------------------------------------------------
'this creates the body of the mail message, the text in quotes can be modified accordingly
'---------------------------------------------------------------------------------------------------
strBody = "Here are the results submitted from " & referer(2)  & vbnewline & vbnewline & "Name: " & realname & vbnewline &  vbnewline & "Email: " & email & vbnewline & strBody & vbnewline &  vbnewline & "############# End of Form #############"

'----------------------------------------------------------------------------------------------------
'checks if a smtp port has been specified, if not it uses the default port 25
'----------------------------------------------------------------------------------------------------
if intport <> 25 then
      intport = intport
else
      intport = 25
end if

'----------------------------------------------------------------------------------------------------
'send the mail message
'----------------------------------------------------------------------------------------------------      
set objMessage = CreateObject("CDO.Message")
objMessage.To = recipient
objMessage.From = email
objMessage.Subject = subject
objMessage.Sender = email
objMessage.Textbody = strBody

'----------------------------------------------------------------------------------------------------
'cdosys configuration setup
'----------------------------------------------------------------------------------------------------
set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort
objConfig.Fields(cdoSMTPServer) = strServer
objConfig.Fields(cdoSMTPServerPort) = intPort
objConfig.Fields(cdoSMTPAuthenticate) = cdoAnonymous
objConfig.Fields.Update
set objMessage.Configuration = objConfig

'----------------------------------------------------------------------------------------------------
'define error handling procedures
'----------------------------------------------------------------------------------------------------
On Error Resume Next
      objMessage.Send
If Err.Number = 0 then
      response.write("Formmail v1.3 processed all operations successfully!")
else
      response.write("Formmail v1.3 detected the following errors:")& "<br>"
      response.write("error no.: ")&err.number & "<br>"
      response.write("description: ")&err.description & "<br>"
      response.end
End If
On Error Goto 0
      
'----------------------------------------------------------------------------------------------------
'send them to the page specified
'----------------------------------------------------------------------------------------------------
Response.Redirect redirect

'####################################################################################################



When I test it from an email, it opens a browser window and refers to an error

if referer(2)
0
 
LVL 4

Accepted Solution

by:
AsbjornG earned 125 total points
ID: 10673941
Here's the formmail script without the referer code:

---------------------------------------------------------------




<%@ Language = vbscript%>
<%option explicit %>
<%server.scripttimeout = 600 %>
'----------------------------------------------------------------------------------------------------
'declare variables
'----------------------------------------------------------------------------------------------------
Dim strFrom, strTo, strSubject, strBody
Dim objMessage, objConfig, strServer, intPort
Dim recipient, redirect, subject, realname, email, required, strEmail1, strEmail2
Dim icounter, query, iloop, query2, query3, i, agree, validation, error0, error0ok

'############################## CONFIGURATION VARIABLES ####################################

'These are the only lines you will need to change
'----------------------------------------------------------------------------------------------------
strServer = "mymailserver.com" 'set which smtp server will be used to send the email. enter ip address or domain name. eg: "xxx.xxx.xxx.xxx" or "smtp.your-domain.com"
intPort = 25 'set the smtp port to be used when sending mail (by default port 25 is used)


'######################################### IMPORTANT NOTICE #########################################
'IMPORTANT: do not modify anything below this line unless you know what you are doing!!
'######################################### IMPORTANT NOTICE #########################################
     
'----------------------------------------------------------------------------------------------------
'information type and CDOSYS constants
'----------------------------------------------------------------------------------------------------
%>
<!--METADATA TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library" -->
<%
'----------------------------------------------------------------------------------------------------
'retrieved default fields
'----------------------------------------------------------------------------------------------------
recipient = request("recipient")
redirect = request("redirect")
subject = request("subject")
required = request("required")
if required = "" then
     required = "recipient,subject,redirect"
else
     required = "recipient,subject,redirect," & required
end if

'----------------------------------------------------------------------------------------------------
'verify the recipient(not tested)
'----------------------------------------------------------------------------------------------------
'trimed_referer = split(referer(2),".")'
'response.write recipient & "<br>" & referer(2) & "=" & trimed_referer(0) & "<br>"
'if trimed_referer(0) = "www" then
'     if InStr(1,recipient,trimed_referer(1),1) = 0 then
'          response.write "recipient don't match the referer"
'          response.end
'     end if
'else
'     if InStr(1,recipient,trimed_referer(0),1) = 0 then
'          response.write "recipient don't match the referer"
'          response.end
'     end if
'end if

'----------------------------------------------------------------------------------------------------
'retrieve form contents and create email fields
'----------------------------------------------------------------------------------------------------
query = Request.ServerVariables("QUERY_STRING")
query = split(query,"&")
query3 = split(required,",")
     For iLoop = Lbound(query) to UBound(query)
          query2 = split(query(iloop),"=")
     
'----------------------------------------------------------------------------------------------------
'form validation, checks required fields are not null
'----------------------------------------------------------------------------------------------------
          for i = LBound(query3) to UBound(query3)
               if query3(i) = query2(0) then
                    if query2(1) = "" then
                         response.write ("you must enter a valid ") & query2(0)
                         response.end
                    end if
               end if
               
               'if query2(0) = "agree" then
                    'if query2(1) <> "on" or query2(1) = "" then
                    '     response.write("You must agree to terms and conditions to enable Formmailv1.3 to execute!")
                    'response.end
                    'end if
               'end if
               
'----------------------------------------------------------------------------------------------------
'form validation, checks a valid email address has been specified
'----------------------------------------------------------------------------------------------------              
               if query2(0) = "email" then
                    trim(query2(0))
                    if len(query2(1))<8 then
                         response.Write("You must specify a valid ") & query2(0)
                         response.end
                    end if
                    if instr(query2(1),"@")=0 and instr(query2(1),".")=0 then
                         response.write query2(1)
                         response.Write("You must specify a valid ") & query2(0)
                         response.end
                    end if
                    strEmail1 = split(query2(1),"@")
                    if len(strEmail1(1))<3 then
                         response.Write("You must specify a valid ") & query2(0)
                         response.end
                    end if
                    strEmail2 = split(strEmail1(1),".")
                    if len(strEmail2(0))<3 then
                         response.Write("You must specify a valid ") & query2(0)
                         response.end
                    end if
                    if len(strEmail2(1))<2 then
                         response.Write("You must specify a valid ") & query2(0)
                         response.end
                    end if
               end if

'----------------------------------------------------------------------------------------------------
'form validation, checks terms and conditions checkbox has been ticked
'----------------------------------------------------------------------------------------------------
               
          Next
          if not query2(0) = "recipient" and not query2(0) = "redirect" and not query2(0) = "subject" and not query2(0) = "realname" and not query2(0) = "email" and not query2(0) = "required" and not query2(0) = "agree" then
               strBody = strBody & vbnewline & vbnewline & query2(0) &": " & query2(1)
          end if
     Next
if email = "" then
     email = "formmail@" & referer(2)
end if
'----------------------------------------------------------------------------------------------------
'replaces any special characters parsed through the query string
'----------------------------------------------------------------------------------------------------
strbody = replace(strbody, "+"," ")
strbody = replace(strbody, "%26%238364%3B","€")
strbody = replace(strbody, "%A1","¡")
strbody = replace(strbody, "%A3","£")
strbody = replace(strbody, "%A8","¨")
strbody = replace(strbody, "%AA","ª")
strbody = replace(strbody, "%AC","¬")
strbody = replace(strbody, "%B4","´")
strbody = replace(strbody, "%B7","·")
strbody = replace(strbody, "%BA","º")
strbody = replace(strbody, "%BF","¿")
strbody = replace(strbody, "%C7","Ç")
strbody = replace(strbody, "%E7","ç")
strbody = replace(strbody, "%0D%0A",vbnewline)
strbody = replace(strbody, "%21","!")
strbody = replace(strbody, "%23","#")
strbody = replace(strbody, "%24","$")
strbody = replace(strbody, "%25","%")
strbody = replace(strbody, "%26","&")
strbody = replace(strbody, "%27","'")
strbody = replace(strbody, "%28","(")
strbody = replace(strbody, "%29",")")
strbody = replace(strbody, "%2B","+")
strbody = replace(strbody, "%2C",",")
strbody = replace(strbody, "%2D","-")
strbody = replace(strbody, "%2E",".")
strbody = replace(strbody, "%2F","/")
strbody = replace(strbody, "%3A",":")
strbody = replace(strbody, "%3B",";")
strbody = replace(strbody, "%3C","<")
strbody = replace(strbody, "%3D","=")
strbody = replace(strbody, "%3E",">")
strbody = replace(strbody, "%3F","?")
strbody = replace(strbody, "%5B","[")
strbody = replace(strbody, "%5C","\")
strbody = replace(strbody, "%5D","]")
strbody = replace(strbody, "%5E","^")
strbody = replace(strbody, "%5F","_")
strbody = replace(strbody, "%60","`")
strbody = replace(strbody, "%7B","{")
strbody = replace(strbody, "%7C","|")
strbody = replace(strbody, "%7D","}")
strbody = replace(strbody, "%7E","~")

'----------------------------------------------------------------------------------------------------
'this creates the body of the mail message, the text in quotes can be modified accordingly
'---------------------------------------------------------------------------------------------------
strBody = "Here are the results submitted from " & referer(2)  & vbnewline & vbnewline & "Name: " & realname & vbnewline &  vbnewline & "Email: " & email & vbnewline & strBody & vbnewline &  vbnewline & "############# End of Form #############"

'----------------------------------------------------------------------------------------------------
'checks if a smtp port has been specified, if not it uses the default port 25
'----------------------------------------------------------------------------------------------------
if intport <> 25 then
     intport = intport
else
     intport = 25
end if

'----------------------------------------------------------------------------------------------------
'send the mail message
'----------------------------------------------------------------------------------------------------    
set objMessage = CreateObject("CDO.Message")
objMessage.To = recipient
objMessage.From = email
objMessage.Subject = subject
objMessage.Sender = email
objMessage.Textbody = strBody

'----------------------------------------------------------------------------------------------------
'cdosys configuration setup
'----------------------------------------------------------------------------------------------------
set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort
objConfig.Fields(cdoSMTPServer) = strServer
objConfig.Fields(cdoSMTPServerPort) = intPort
objConfig.Fields(cdoSMTPAuthenticate) = cdoAnonymous
objConfig.Fields.Update
set objMessage.Configuration = objConfig

'----------------------------------------------------------------------------------------------------
'define error handling procedures
'----------------------------------------------------------------------------------------------------
On Error Resume Next
     objMessage.Send
If Err.Number = 0 then
     response.write("Formmail v1.3 processed all operations successfully!")
else
     response.write("Formmail v1.3 detected the following errors:")& "<br>"
     response.write("error no.: ")&err.number & "<br>"
     response.write("description: ")&err.description & "<br>"
     response.end
End If
On Error Goto 0
     
'----------------------------------------------------------------------------------------------------
'send them to the page specified
'----------------------------------------------------------------------------------------------------
Response.Redirect redirect

'############################################################################################

Please let me know if you are still getting errors, as there may be other reasons why it doesn't work!

Cheers,

Asbjorn
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

705 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

20 Experts available now in Live!

Get 1:1 Help Now