Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Email String Problem 1

Status
Not open for further replies.
Mar 4, 2001
43
0
0
US
I'm trying to use ASP to write a mailto: link that will compose the entire email from form data. The ASP code is pretty simple:
Code:
<%@LANGUAGE="VBSCRIPT"%>
<%
Dim strEmail

strEmail="Name: " &  Request.Form("name")
strEmail=strEmail & "%0DAddress Line 1: " &  Request.Form("address1")
strEmail=strEmail & "%0DAddress Line 2: " &  Request.Form("address2")
strEmail=strEmail & "%0DCity: " &  Request.Form("city")
strEmail=strEmail & "%0DState: " &  Request.Form("state")
strEmail=strEmail & "%0DZIP Code: " &  Request.Form("zip")
strEmail=strEmail & "%0DPhone Number: " &  Request.Form("phone")
strEmail=strEmail & "%0DeMail Address: " &  Request.Form("email")
strEmail=strEmail & "%0DCareer Objective: " &  Request.Form("objective")
strEmail=strEmail & "%0DApplying for what position: " &  Request.Form("position")
strEmail=strEmail & "%0DDate Available: " &  Request.Form("avalDate")
strEmail=strEmail & "%0DCertifications or Registrations: " &  Request.Form("certreg")
strEmail=strEmail & "%0DYears of Experiance: " &  Request.Form("yearexp")
strEmail=strEmail & "%0DPositions previously held: " &  Request.Form("posheld")
strEmail=strEmail & "%0DDegree or Highest Grade Completed: " &  Request.Form("deggrade")
strEmail=strEmail & "%0DYear of Graduation: " &  Request.Form("yeargrad")
strEmail=strEmail & "%0DCollege or University : " & Request.Form("college")
strEmail=strEmail & "%0DMajor: " &  Request.Form("major")
strEmail=strEmail & "%0DArea of Emphasis: " &  Request.Form("emphasis")
strEmail=strEmail & "%0DProfessional Affiliations: " & Request.Form("professional")
strEmail=strEmail & "%0DHow did you hear about HEA?: " &  Request.Form("hear")
strEmail=strEmail & "%0DWhy should we hire you?: " &  Request.Form("whyhire")

strEmail= replace(strEmail, " ", "%20")
strEmail= replace(strEmail, "!", "%21")
'strEmail= replace(strEmail, """", "%22")
strEmail= replace(strEmail, "#", "%23")
strEmail= replace(strEmail, "$", "%24")
strEmail= replace(strEmail, "%", "%25")
strEmail= replace(strEmail, "&", "%26")
'strEmail= replace(strEmail, "'", "%27")
strEmail= replace(strEmail, "(", "%28")
strEmail= replace(strEmail, ")", "%29")
strEmail= replace(strEmail, ",", "%2C")
strEmail= replace(strEmail, ":", "%3A")
strEmail= replace(strEmail, ";", "%3B")
strEmail= replace(strEmail, "< ", "%3C")
strEmail= replace(strEmail, "=", "%3D")
strEmail= replace(strEmail, ">", "%3E")
strEmail= replace(strEmail, "[", "%5B")
strEmail= replace(strEmail, "\", "%5C")
strEmail= replace(strEmail, "]", "%5D")
strEmail= replace(strEmail, "^", "%5E")
strEmail= replace(strEmail, "`", "%60")
strEmail= replace(strEmail, "{", "%7B")
strEmail= replace(strEmail, "|", "%7C")
strEmail= replace(strEmail, "}", "%7D")
strEmail= replace(strEmail, "~", "%7E")
strEmail= replace(strEmail, "?", "%3F")
%>
This is then appended to the link via:
Code:
<%Response.Write "<a href='mailto:test@test.com?Subject=Test%20Email&Body=" & strEmail & "'>Email link</a>"%>
With no data in the form, this produces a lovely formatted email. When I pass data to the string from the form I get a mess in the body of the mail.
Code:
Name:%20Test%20User%0DAddress%20Line%201:%201234%20Test%20St%0DAddress%20Line%202:%20Ap%20t%23%202%0DCity:%20Anywhere%0DState:%20PA%0DZIP%20Code:%2012345%0DPhone%20Number:%20800-555-1234%0DeMail%20Address:%20nonya@bizness.com%0DCareer%20Objective:%20%0DApplying%20for%20what%20position:%20%0DDate%20Available:%20%0DCertifications%20or%20Registrations:%20%0DYears%20of%20Experiance:%20%0DPositions%20previously%20held:%20%0DDegree%20or%20Highest%20Grade%20Completed:%20%0DYear%20of%20Graduation:%20%0DCollege%20or%20University%20:%20%0DMajor:%20%0DArea%20of%20Emphasis:%20%0DProfessional%20Affiliations:%20%0DHow%20did%20you%20hear%20about%20HEA?:%20%0DWhy%20should%20we%20hire%20you?:%20
I'm assuming it's a simple error with my hex code conversion script, but darned if I can find it. Any help or pointers would be appreciated.
 
Try and use server.URLEncode() or server.HTMLEncode() without your hex conversions.
 
Thanks, that worked. Still not catching every single possible problem character, but close enough, and formatting the string properly.
 
Still not catching every single possible problem character

Which characters is URLEncode not taking care of?

By definition, it should be taking care of all problem characters for passing info via a URL.

[monkey][snake] <.
 
I see what you're getting at.

Valid characters for the email as opposed to passing the URL.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top