1

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=myclient@myclientsdomain.com

...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= myclient@clientsdomain.com

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 = “myemail@mydomain.com"
sFormDomain = “mydomain.com"
sFormSubject = "Enquiry From Website."
sFormDestination = “me@mydomain.com"
'sFormDestination = “mail@mydomain.com"
'============================================
' 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=myclient@myclientsdomain.com 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?

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
  • Can you not just use `<` `>` around your e-mail address to force outlook to recognise it as an e-mail address, works for hyper-links? – user692942 Jul 31 '14 at 09:07
  • If it's a HTML format e-mail you could use `&nbsp` (non breaking space). – user692942 Jul 31 '14 at 09:10
  • I can't see from that code how something like `email=myclient@myclientsdomain.com` is being generated?? – user692942 Jul 31 '14 at 09:14
  • Hi Lankymart - I'm afraid these won't work - I've added why at the bottom of the original post. Thanks anyway. – user3894841 Jul 31 '14 at 09:33
  • Ok, why do you need the form element names passed into the e-mail? That is a by product of using `Split()` to break up your `Request.Form` collection. Why not use `For Each item In Request.Forms`? – user692942 Jul 31 '14 at 09:38
  • This was an asp script I found online. I only have a very basic understanding of how it works. I think I have the solution - I just need a leading space added. What I don't know is how to edit my code to do this. Thanks. – user3894841 Jul 31 '14 at 09:43

1 Answers1

0

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.

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • Awesome - I'll try it. Give me 10 mins! I owe you if this works!! – user3894841 Jul 31 '14 at 09:48
  • @user3894841 Couple of typos corrected and added method that iterates through the `Request.Form` collection which would be my preferred approach, less mess no need to escape characters etc. – user692942 Jul 31 '14 at 10:05
  • For these 2 methods of emailing the values without outputting name=value... What part of the original code do I need to remove? I'm not sure where your new code should be inserted. Sorry, I'm no coder - aware this is a noob question! Apologies. – user3894841 Jul 31 '14 at 10:24
  • @user3894841 Glad to hear it, to be honest though if you get chance think about using the third method which gives you a lot more control. – user692942 Jul 31 '14 at 10:24
  • @user3894841 I've updated my answer to show what should be replaced in the code to use the third method. Good luck. – user692942 Jul 31 '14 at 10:27
  • Thanks so much. I need a coder from time to time (paid). Can you PM me an email address if you're interested? Thank you again! – user3894841 Jul 31 '14 at 10:46
  • @user3894841 Appreciate the offer but full-time already. If it helped, you might consider taking a look at this [What should I do when someone answers my question?](http://stackoverflow.com/help/someone-answers). – user692942 Jul 31 '14 at 10:52