This is a discussion on "sort mailbody" within the Classic ASP section. This forum, and the thread "sort mailbody are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
sort mailbody
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
sort mailbody
Hi
i have a form which is send via a formhandler. unfortunately the field in the mail aren't sortetd at all... i saw a post in this forum where the solution to sort a mail is to put the fields in an array and then sort it. but there you have to name all the fields. As our formhandler serves for different forms, i can't name the fields... can anybody tell me how i could put the fields in an array and sort them when i don't know how many fields i have and also don't know what the fieldnames are? our script is as follows: ... <% Function fctSendMail(strFrom, strTo, strSubject, strBody, strError) strOS = Request.ServerVariables("SERVER_SOFTWARE") strOSVersion = Mid(strOS, InStrRev(strOS,"/")+1, 1) If strOSVersion >= 5 Then ' on Windows 2000 and higher we can use CDOSYS Set objMessage = CreateObject("CDO.Message") Set objConfig = CreateObject("CDO.Configuration") If Application("parMailServer") = "localhost" Then objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPickup Else objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort objConfig.Fields(cdoSMTPServer) = Application("parMailServer") objConfig.Fields(cdoSMTPServerPort) = 25 objConfig.Fields(cdoSMTPAuthenticate) = cdoAnonymous End If objConfig.Fields.Update ' Bind configuration to message Set objMessage.Configuration = objConfig objMessage.From = strFrom objMessage.Sender = strFrom objMessage.To = strTo objMessage.Subject = strSubject objMessage.TextBody = strBody On Error Resume Next objMessage.Send If Err.Number = 0 Then fctSendMail = True Else fctSendMail = False strError = Err.Description Err.Number = 0 End If On Error Goto 0 Else ' on NT4 we have to use CDONTS. No error handling is provided Set objMail = CreateObject("CDONTS.NewMail") With objMail .From = strFrom .To = strTo .Subject = strSubject .Body = strBody .Send End With Set objMail = Nothing End If End Function strFormErrorMail = "" strFormErrorScreen = "" strBodyMail = "" strBodyScreen = "" strMailError = "" strSubject = Request.Form("Subject") ' First make sure all parameters needed for mail sending have been passed If Request.Form("To") & " " = " " Then strFormErrorMail = strFormErrorMail & "- " & Application("txtFormErrorNoRecipient" & conCurLang) & vbCrLf strFormErrorScreen = strFormErrorScreen & "- " & Application("txtFormErrorNoRecipient" & conCurLang) & " " & vbCrLf End If If Request.Form("From") & " " = " " Then strFormErrorMail = strFormErrorMail & "- " & Application("txtFormErrorNoSender" & conCurLang) & vbCrLf strFormErrorScreen = strFormErrorScreen & "- " & Application("txtFormErrorNoSender" & conCurLang) & " " & vbCrLf End If If strSubject & " " = " " Then strSubject = Application("txtFormDefaultSubject" & conCurLang) & " " & Request.ServerVariables("HTTP_REFERER") End If If strFormErrorMail = "" Then ' We have all necessary information to try sending the form contents by e-mail For Each Field in Request.Form strBodyScreen = strBodyScreen & Field & ": " & Request.Form(Field) & " " & vbCrLf strBodyMail = strBodyMail & Field & ": " & Request.Form(Field) & vbCrLf Next If fctSendMail(Request.Form("From"), Request.Form("To"), strSubject, strBodyMail, strMailError) Then Response.Write " " & Application("txtFormSuccessMessage" & conCurLang) & " " & Request.Form("To") & ":</p>" Response.Write " " & strBodyScreen & "</p>" Else Response.Write " " & Application("txtFormErrorSending" & conCurLang) & ":</p>" Response.Write " " & strMailError & "</p>" ' Send notification to head webmaster strSubject = Application("txtFormErrorMessage" & conCurLang) & " " & Request.ServerVariables("HTTP_REFERER") strBodyMail = Application("txtFormErrorSending" & conCurLang) & ": " & vbCrLf & strMailError If fctSendMail(Application("parWebmasterEmail"), Application("parWebmasterEmail"), strSubject, strBodyMail, strMailError) Then Response.Write " " & Application("txtFormErrorSentToWebmaster" & conCurLang) & "</p>" End If End If Else ' Some parameters were missing, notify the user on-screen and the Webmaster by email Response.Write " " & Application("txtFormErrorMessage" & conCurLang) & " " & Request.ServerVariables("HTTP_REFERER") & ": " Response.Write strFormErrorScreen ' Send notification to head webmaster strSubject = Application("txtFormErrorMessage" & conCurLang) & " " & Request.ServerVariables("HTTP_REFERER") strBodyMail = strFormErrorMail & vbCrLf & Trim(Application("txtContentmasterText" & conCurLang)) & ": " & Request.Form("Contentmaster") If fctSendMail(Application("parWebmasterEmail"), Application("parWebmasterEmail"), strSubject, strBodyMail, strMailError) Then Response.Write " " & Application("txtFormErrorSentToWebmaster" & conCurLang) & "</p>" End If End If %> thanx in advance! |
|
|
|
|||
|
... i guess i would have to put this in an array..
For Each Field in Request.Form strBodyScreen = strBodyScreen & Field & ": " & Request.Form(Field) & " " & vbCrLf strBodyMail = strBodyMail & Field & ": " & Request.Form(Field) & vbCrLf Next |
|
|||
|
It looks like you're pretty familiar with ASP so I'll limit my reply to the concept, but if you need help with the code just ask.
You'll want to add a number to the beginning of each field name that indicates what order the items should show up in the results, make sure you use a leading zero if there's more than 10, for example: 01FirstName 02LastName 04State 03City ... 17Zipcode Then in your form handler you'd use one of the many alphabetizing/sorting routines that you can find on the web along with the For Each loop to sort the form data. This will put it in the order you specify with your numbering. Finally, you'll just need to strip off the beginning numbers of the fieldname when you output them using something like Fieldname=right(Field,len(Field)-2) The tricky bit is the alphabetizing as you'd need to move the form data into arrays before you can order them. I'll put some code together for this and post it shortly just in case you or someone else needs it. |
|
|||
|
OK, here's the code. Of course you'll want to modify it to build the body string for your email rather than write out the values to the page. I included some HTML to demonstrate the code.
|
|
|||
|
Thanx a lot!! it worked!
..actually, I hade to name my fields '_01...', 'cause without the '_' i got an error (maybe because I validate some of my fields?) but nevertheless the fields are now sortet in my Mail!! ehm.. I got another question... I have the hidden fields 'From', 'To', 'Subject' and 'Title' and the Submit-Button which also appear in the Mailbody.. like: From: xy@mail.com Senden: Senden Subject: Mitarbeiterumfrage 2003 Title: Besten Dank To: xy@mail.com _01Anstellungsbedingungen: 1 _02Infrastruktur: 2 _03Arbeitsabläufe: 3 _04Arbeitsklima: 4 _05InfoPersonalpolitik: 56 _06Sonstiges: 7 _07Geschlecht: weiblich _08Alter: bis 19 _09Führungsposition: ja _10Arbeitsbereich: Innendienst _11Arbeitsplatz: RD _12Name: _13Geschäftsstelle: . is there a way to eliminate them from the mailbody?? (i can't eliminate from!) thanx again in advance for any advice!! |
|
|||
|
ok... i got a workaround...
as i know, that I only want the fields beginning with a _ in my mail, i just do the following: ' display the data for i = 0 to formcount-1 if left(aFieldName(i),1) = "_" then strBodyScreen = strBodyScreen & right(aFieldName(i),len(aFieldName(i))-3)& ": " & aFieldValue(i) & " " & vbCrLf strBodyMail = strBodyMail & right(aFieldName(i),len(aFieldName(i))-3)& ": " & aFieldValue(i) & vbCrLf end if next |
|
|||
|
Yep, that would have been my suggestion.
|
|
|||
|
my form now works fine...but some users asked me, if I could give a structure to the mailbody...
like now, the body looks like: NAME: Sabine MAIL: xy@mail.com SAMPLETEXT: this is a test... a.s.o. ..but the users want something that looks more like a table: NAME: sabine MAIL: xy@mail.com SAMPLETEXT: this is a test... a.s.o. any advice?? |
![]() |
| Tags |
| sort, mailbody |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sort a three dimensional array?? | nate2099 | PHP Forum | 3 | Aug 1st, 2007 16:21 |
| Some sort of database in flash? | Throntel | Flash & Multimedia Forum | 3 | Jan 6th, 2007 05:54 |
| trying to sort out a disjointed rollover problem | seanollett | JavaScript Forum | 0 | Apr 23rd, 2006 08:25 |
| filter xml and sort xml | alcove | Other Programming Languages | 1 | Apr 17th, 2006 03:01 |
| New Member needs help to sort out website! | nico7_uk | Introduce Yourself | 1 | Jun 29th, 2005 09:17 |