I have the following asp code which receives the POST data from an HTML page and then sends an e-mail with the data to a recipient. All works fine except when exten开发者_运维技巧ded characters are in any of the form fields such as for example
Högberg and Pensevägen
They end up as
Hà ¶gberg and Pensevà ¤gen13A
How do I encode these so that the e-mail received will show the correct characters Is there a encodeURIComponent() for ASP and will that work?
<%
Option Explicit
Dim referer
Dim siteurl
Dim email_from
Dim email_to
Dim strMsg
referer = Request.ServerVariables("HTTP_REFERER")
siteurl = "www.example.com"
email_from = "somename@example.com"
email_to = "somename@example.com"
strMsg = "Order ID : " & request.form("ordernumber") & "<br>"
strMsg=strMsg+ "Order Date : " & request.form("orderdate") & "<br>"
strMsg=strMsg+ "Ship Date : " & request.form("shipdate") & "<br>"
strMsg=strMsg+ "Current Status : " & request.form("currentstatus") & "<br>"
strMsg=strMsg+ "Current Selected Ship Method : " & request.form("currentselectedmethod") & "<br>"
strMsg=strMsg+ "Shipping Method : " & request.form("shippingmethod") & "<br>"
strMsg=strMsg+ "Tracking No : " & request.form("trackingnumber") & "<br>"
strMsg=strMsg+ "Payment Method : " & request.form("paymentmethod") & "<br>"
strMsg=strMsg+ "Customer ID : " & request.form("customerid") & "<br>"
strMsg=strMsg+ "Ship Company Name : " & request.form("companyName") & "<br>"
strMsg=strMsg+ "Ship Name : " & request.form("personName") & "<br>"
strMsg=strMsg+ "Ship Address1 : " & request.form("address1") & "<br>"
strMsg=strMsg+ "Ship Address2 : " & request.form("address2") & "<br>"
strMsg=strMsg+ "Ship City : " & request.form("city") & "<br>"
strMsg=strMsg+ "Ship State : " & request.form("state") & "<br>"
strMsg=strMsg+ "Ship Zip : " & request.form("zip") & "<br>"
strMsg=strMsg+ "Ship Country : " & request.form("country") & "<br>"
strMsg=strMsg+ "Ship Phone : " & request.form("phone") & "<br>"
strMsg=strMsg+ "Customer Email Address : " & request.form("email_address") & "<br>"
strMsg=strMsg+ "Total Received : " & request.form("totalreceived") & "<br>"
strMsg=strMsg+ "Total Due : " & request.form("totaldue") & "<br>"
if InStr(referer, siteurl ) > 0 Then
Dim HTTPRequest
Set HTTPRequest = CreateObject("WinHTTP.WinHTTPRequest.5.1")
HTTPRequest.Open "POST", "http://" & Request.ServerVariables("LOCAL_ADDR") & "/email.asp", False
HTTPRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTPRequest.SetRequestHeader "Host", Request.ServerVariables("SERVER_NAME")
HTTPRequest.Send _
"VsmtpKey=" & "1234-5678-8902451525-5525" &_
"&Subject=" & Server.URLEncode("Order ") & Server.URLEncode(request.form("ordernumber")) & Server.URLEncode(" Shipped") &_
"&FromEmailAddress=" & email_from &_
"&ToEmailAddress=" & email_to &_
"&Body_HTML=" & Server.URLEncode(strMsg) &_
response.write(strMsg)
response.write(HTTPRequest.ResponseText)
End If
Set HTTPRequest = Nothing
%>
Have you tried this ?
Server.HTMLEncode( sWeirdValue )
Have you tried to alter the way the server parses the character set ? I remember having to use:
Response.CharSet = "windows-1252"
Also try to use the Codepage property on top of your script
Response.CodePage = 1252
If this is not set, the page will be encoded by the server's default.
Codepage 65001 is used for utf-8 characterset, while i assume you will be needing the ANSI set here.
精彩评论