简体   繁体   English

ASP电子邮件表单-尝试插入前导空格

[英]asp email form - trying to insert leading space

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: 我的一位客户报告说,当他收到生成的电子邮件时,Outlook正在操纵该行:

email=myclient@myclientsdomain.com

...to include the prefix "email=" as if that's part of the email! ...包括前缀“ email =“,就好像这是电子邮件的一部分一样! (Silly Outlook!) (愚蠢的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. 总之,由于电子邮件和前缀之间没有任何空格,因此在创建电子邮件链接时,Outlook会包括前缀。

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. Lankymart-Outlooks看到文本字符串email=myclient@myclientsdomain.com在中间包含一个@符号,并将整个内容解释为电子邮件地址-这样,它使整个内容成为可单击的电子邮件链接。 If my form could generate a non breaking space, Outlook would still make that an email link but without the unwanted prefix included. 如果我的表单可以产生一个不间断的空格,Outlook仍将创建该电子邮件链接,但不包含不需要的前缀。

I can't use &nbsp - I don't know how to automatically insert it using the script (this is what I'm asking). 我不能使用&nbsp-我不知道如何使用脚本自动插入它(这是我要的)。 Perhaps you meant on my html form page - this won't "carry through" to the email that's batched up and sent. 也许您的意思是在我的html表单页面上-这不会“传递”到已批量发送的电子邮件中。

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. 方括号具有相同的问题-如果asp表单可以以某种方式自动为我插入它们,则电子邮件将到达,Outlook可能会正确显示它们-使我的表单执行此操作是我需要知道的部分。 (I feel a leading space might be better as this will definitely work) (我认为领先的空间可能会更好,因为这肯定会起作用)

Any other ideas? 还有其他想法吗?

It's simple just use Replace() to identify the equals and add the &nbsp (Non-breaking space). 这很简单,只需使用Replace()来确定等号并添加&nbsp (不间断空格)。

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() ; 或者尝试使用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; 如果您只希望表单值而不输出name=value可以遍历Request.Form集合,例如;

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; 这将是我遍历Request.Form集合的首选方法,如果您想要键值对方法name=value您仍然可以这样做。

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. 因为您遍历Request.Form集合而不是使用Split()来构建Array并遍历该数组,所以您不必再进行所有字符串清理,这就是使用For Each方法的好处之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM