asp email form - trying to insert leading space

147 views Asked by At

I used this script on my website to collect enquiry form information from visitors. One of my clients reports that when he receives the email that's generated, Outlook is manipulating the line:

[email protected]

...to include the prefix "email=" as if that's part of the email! (Silly Outlook!)

I need to alter my code so a leading space is inserted immediately before the email address so it looks more like this:

email= [email protected]

That way, when my client clicks on the email to reply to the user, the correct email is used (the one without the prefix attached to the front of the email!)

In summary Outlook is including the prefix when it creates an email link because of the absence of any space between the email and the prefix.

I'm not much of a coder and extensive searching has failed me. I tried lots of suggestions but my form seems to either fail or no fix happens.

<!--START CODE FOR SENDFORM.ASP -->
<%@ LANGUAGE="VBScript" %>
<%
Dim sFormTitle, sFormSender, sFormSubject, sFormDestination

'============================================
' You only need to change the details below!
'============================================
sFormTitle = "enquiries"
sFormSender = “[email protected]"
sFormDomain = “mydomain.com"
sFormSubject = "Enquiry From Website."
sFormDestination = “[email protected]"
'sFormDestination = “[email protected]"
'============================================
' And that's it!
'============================================

Dim sRawForm, aFormArray, sElement, sFormData

sRawForm = request.form
aFormArray = Split(sRawForm, "&")
for i = 0 to UBOUND(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace( sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
next
%>

<%
Dim sRecipients, sBody, sSubject
sRecipients = Request.Form( sFormDestination )
sBody = sFormData
sSubject = sFormSubject

dim msg
set msg = Server.CreateOBject( "JMail.SMTPMail" )
msg.Logging = true
msg.silent = true
msg.Sender = sFormSender
msg.SenderName = sFormTitle
msg.AddRecipient sFormDestination
msg.Subject = sSubject
msg.Body = sBody
msg.ServerAddress = "IP GOES HERE - REMOVED IT FOR THIS POSTING"


if not msg.Execute then
Response.redirect "http://mydomain.co.uk/sorry.html"
else
Response.redirect "http://mydomain.co.uk/thanks.html"
end if
%>
<!--END CODE FOR SENDFORM.ASP -->

EDIT BELOW IN RESPONSE TO LANKYMART'S SUGGESTIONS:

Lankymart - Outlooks sees the text string [email protected] contains an @ symbol in the middle and interprets the whole thing to be the email address - as such it makes the whole thing a clickable email link. If my form could generate a non breaking space, Outlook would still make that an email link but without the unwanted prefix included.

I can't use &nbsp - I don't know how to automatically insert it using the script (this is what I'm asking). Perhaps you meant on my html form page - this won't "carry through" to the email that's batched up and sent.

The square brackets have the same issue - if the asp form could somehow automatically insert these for me, the email will arrive and Outlook might display it correctly - getting my form to do this is the part I need to know. (I feel a leading space might be better as this will definitely work)

Any other ideas?

1

There are 1 answers

6
user692942 On BEST ANSWER

It's simple just use Replace() to identify the equals and add the &nbsp (Non-breaking space).

sRawForm = Request.Form
aFormArray = Split(sRawForm, "&")
For i = 0 To UBound(aFormArray)
  sElement = Unescape(aFormArray(i))
  sElement = Replace(sElement, "=", "&nbsp;=")
  sElement = Replace(sElement, "+", " " )
  sFormData = sFormData & sElement & vbCrLf
Next

Or to try the < > method using Replace();

sRawForm = Request.Form
aFormArray = Split(sRawForm, "&")
For i = 0 To UBound(aFormArray)
  sElement = Unescape(aFormArray(i))
  sElement = Replace(sElement, "=", "=<") & ">"
  sElement = Replace(sElement, "+", " " )
  sFormData = sFormData & sElement & vbCrLf
Next 

If you just want the form values without outputting name=value just iterate through the Request.Form collection like;

Dim element

For Each element In Request.Form
  sFormData = sFormData & element.Value & vbCrLf
Next

This would be my preferred method for iterating through the Request.Form collection, if you want the key value pair approach name=value you can still do that like this;

Dim element

For Each element In Request.Form
  'Both &nbsp; and < > methods shown but < > preferred.
  'sFormData = sFormData & element.Name & "=&nbsp;" & element.Value & vbCrLf
  sFormData = sFormData & element.Name
  'Only add < > if it's the email element.
  If element.Name = "email" Then
    sFormData = sFormData & "=<" & element.Value & ">" & vbCrLf 
  Else
    sFormData = sFormData & "=" & element.Value & vbCrLf 
  End If
Next

Update: In reply to the question in the comments the above code should replace;

sRawForm = request.form
aFormArray = Split(sRawForm, "&")
for i = 0 to UBOUND(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace( sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
next

Because your iterating through the Request.Form collection instead of using Split() to build an Array and loop through that, you no longer have to do all the string clean-up, this is one of the benefits of using the For Each approach.