Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-07-2013, 04:09 PM   PM User | #1
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
store details in excel file using asp form mailer

sir i have created an .asp script with the help of your site, i have gone through some forum posts and with some r&d i have accomplish the task howerver i need to do one more thing and i am unable to develop it myself. i tried some r&d but failed therefore i seek your help. please do help me

i have an contact us form in my website and i have created an asp script for it and it is working fine. now i need a little more from it.

i need that whenever any person fills the form to contact me his details get stored in an excel file placed in a folder in the website and the date get append in to it subsequently. i know it is possible but i dont how how to code it in the same asp script. my script is as under

--------------------------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim strEmailMessage
Dim myMail
Dim UserIPAddress
UserIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserIPAddress = "" Then
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
strFeedTitle = Request.Form("Title")
strFeedName = Request.Form("Name")
strFeedEmail = Request.Form("Email")
strFeedCell = Request.Form("Cell")
strFeedCompany = Request.Form("Company")
strFeedSubject = Request.Form("Subject")
strFeedMessage = Request.Form("Message")

strFeedMessage="<html><body style='font-family:Verdana; font-size:12px'><h2 style='color:#06F; font-family:Verdana'>MESSAGE SUMMARY </h2><hr><br /><br /><table width='100%' border='0' cellspacing='4' cellpadding='10' style='color:#2C3038; font-family:Verdana; font-size:13px'> <tr> <td width='20%' align=right bgcolor='#f1f1f1'><strong>TITLE</strong></td> <td width='80%' bgcolor='#f1f1f1'>"& strFeedTitle &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>NAME</strong></td> <td bgcolor='#f5f5f5'><strong>"& strFeedName &" </strong></td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>EMAIL</strong></td> <td bgcolor='#f1f1f1'>"& strFeedEmail &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>PHONE</strong></td> <td bgcolor='#f5f5f5'>"& strFeedCell &" </td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>COMPANY</strong></td> <td bgcolor='#f1f1f1'>"& strFeedCompany &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>SUBJECT</strong></td> <td bgcolor='#f5f5f5'>"& strFeedSubject &" </td> </tr> <tr align=right> <td align='right' bgcolor='#f1f1f1'><strong>MESSAGE</strong></td> <td height='auto' align='left' valign='top' bgcolor='#FFFFFF'>"& strFeedMessage &"</td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>IP ADD</strong></td> <td align='left' bgcolor='#f1f1f1'>"& UserIPAddress &" </td> </tr></table></body></html>"

Set myMail=CreateObject("CDO.Message")
myMail.Subject="Msg. from Website "
myMail.From=strFeedEmail
myMail.To="info@addboss.in"
myMail.HtmlBody=strFeedMessage
myMail.Send
set myMail=nothing

strAutoReply="<html><body style='color:#333; font-family:Verdana; font-size:12px'><p>Dear<span style='font-weight:bold'> " & strFeedTitle & " " & strFeedName & "</span></p><p>Thanks for contacting us</p><p>Your mail has been submitted successfully and we will get back to you within three working days</p></p><br /><p>Regards</p><p>ADDBOSS <br> Corporate services consultants <br> www.addboss.in <br><br><br><br><br><hr><p style='color:#595959; font-size:10px;'><span style='font-weight:bold'>Note: </span>This is an auto response-back mail from the server of ADDBOSS for the acknowledgement of your submission. Please do not reply on this mail. However, if you need to contact us any further you may directly write to us on info@addboss.in</p></body></html>"


Set myMail2=CreateObject("CDO.Message")
myMail2.Subject="Auto-Reply from ADDBOSS"
myMail2.From="no-reply@addboss.in"
myMail2.To=strFeedEmail
myMail2.Htmlbody=strAutoReply
myMail2.Send
set myMail2=nothing
response.redirect("../thankyou.html")
%>
--------------------------------------------------------------
please help me.
if you need some more details please ask me and i will provide it here.


thanks
rshekhar21 is offline   Reply With Quote
Old 02-07-2013, 08:59 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Storing in Excel file is not the best idea. The file has to be *LOCKED* for the entire duration of the update as you will have problems if 2 people ever tried to add at the same time.

Better would be an Access database.

Even better would be a MySQL or SQL Server database.

A possible alternative would be to add to the end of a ".CSV" file. Excel can open up ".CSV" files and they don't have as many problems as storing to Excel file would.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-08-2013, 09:36 AM   PM User | #3
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
sir

thanks for this advice.

so, could you please tell me the process of how apply access database to this system step by step. or if csv can be implemented without any hazel the how to apply that.

i will be grateful to you
rshekhar21 is offline   Reply With Quote
Old 02-08-2013, 07:41 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Using the CSV file is by far the easiest.

Just before the Response.Redirect line at the end, add this code:
Code:
CONST QT = """" ' creates a single quote mark

' put the items into the array in whatever order you prefer:
csvItems = Array( UserIPAddress, strFeedTitle, strFeedName, strFeedEmail, _
                strFeedCell, strFeedCompany, strFeedSubject, strFeedMessage )

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set csv = FSO.OpenTextFile( Server.MapPath("emailLog.csv"), 8, True )
csv.WriteLine QT & Join( csvItems, QT & "," & QT ) & QT
csv.Close
Set FSO = Nothing

response.redirect("../thankyou.html")

%>
The only thing to watch out for is here:
Code:
         Server.MapPath("emailLog.csv")
Aside from the fact that you can use any file name of your choice, though it should end in ".csv", that code as written probably won't work. That says "find the CSV text file in the same directory as this code." Almost surely the directory with the code will *NOT* be writable.

Typically, you will have a writable "data" directory that is either a subdirectory of the code directory or is "besided" the code subdirectory. So you will likely need something such as
Code:
    Server.MapPath("data/emailLog.csv")
or
    Server.MapPath("/data/emailLog.csv")
or 
    Server.MapPath("../data/emailLog.csv")
You will have to figure that part out based on the directory structure on your machine.

This code should write out a CSV file that looks like
Code:
"68.128.3.7","Amalgamated Widgets","Today's Widget Report","...", etc.
TWO CAUTIONS: In a ".csv" file like this, *NONE* of the field may contain *EITHER* quote marks or new line characters.

If you are unsure if they might, you could use a "cleaner" function something like:
Code:
Function clean( txt )
    clean = Replace( Replace( Replace( txt, """","'" ), vbCR, " ", vbLF, " " )
End Function
And then construct the array using that function:
Code:
csvItems = Array( UserIPAddress, clean(strFeedTitle), clean(strFeedName), _
                clean(strFeedEmail), clean(strFeedCell), clean(strFeedCompany), _
                clean(strFeedSubject), clean(strFeedMessage) )
Give it a shot!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-09-2013, 10:27 AM   PM User | #5
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
So grateful to you,
i really owe you a lot, it was overwhelming.

the code worked so perfectly.

first off all i got afraid to implement this but than i slowly read all the lines and finally implement with the first step by copying the first block of code in my asp file and then uploaded the file to the server.

i than filled the form and checked the folder on the server, there was a file created with the name emaillog.csv. i then download the file and opened in excel and it got opened with all the details of the form. the first test got passed.

now i filled the form again and checked the folder, i simply refresh the folder in my fpt Clint (filezila) and i noticed that the size of the emaillog.csv has increased by a bit.

i download the file again and checked the values. i cant tell you my happiness, the purpose i have been looking for like hell is solved. the data is getting appended to the previous data. i mean now i will have this same file to collect all the data of the form filler.

this is so amazing, i mean just a few line of codes have done this work.

really a programmer can do anything.

i am so thankful to you. if you don't mind can i know you name and email id. or you can send me mail on rsingh21.jan13@gmail.com

raj
rshekhar21 is offline   Reply With Quote
Old 02-09-2013, 10:52 AM   PM User | #6
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
sir as my problem is almost over, however there is one thing left, which is not an irk, but if something can be done for it then it will be so nice of you.

strFeedMessage="<html><body style='font-family:Verdana; font-size:12px'><h2 style='color:#06F; font-family:Verdana'>MESSAGE SUMMARY </h2><hr><br /><br /><table width='100%' border='0' cellspacing='4' cellpadding='10' style='color:#2C3038; font-family:Verdana; font-size:13px'> <tr> <td width='20%' align=right bgcolor='#f1f1f1'><strong>TITLE</strong></td> <td width='80%' bgcolor='#f1f1f1'>"& strFeedTitle &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>NAME</strong></td> <td bgcolor='#f5f5f5'><strong>"& strFeedName &" </strong></td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>EMAIL</strong></td> <td bgcolor='#f1f1f1'>"& strFeedEmail &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>PHONE</strong></td> <td bgcolor='#f5f5f5'>"& strFeedCell &" </td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>COMPANY</strong></td> <td bgcolor='#f1f1f1'>"& strFeedCompany &" </td> </tr> <tr> <td align=right bgcolor='#f5f5f5'><strong>SUBJECT</strong></td> <td bgcolor='#f5f5f5'>"& strFeedSubject &" </td> </tr> <tr align=right> <td align='right' bgcolor='#f1f1f1'><strong>MESSAGE</strong></td> <td height='auto' align='left' valign='top' bgcolor='#FFFFFF'>"& strFeedMessage &"</td> </tr> <tr> <td align=right bgcolor='#f1f1f1'><strong>IP ADD</strong></td> <td align='left' bgcolor='#f1f1f1'>"& UserIPAddress &" </td> </tr></table></body></html>"


this block of coed is the email body which i receive in my email clinte.

all the details comes as it suppose to come, i only want a little change in the message area ie. strFeedMessage,

the message comes like a block of pragraph, i mean no tabs not line breaks, just a pragraph,

to explain this, for example if i fill the form and in the message area i write

"hi,
i have given my order,
plese chek to it

thanks"

now when i receive this mail, i simply get the above text as

"hi, may i have give my order, please check to it thanks."

although i can understand it but if it comes in a defined was as it was then it would be more better.

i tried to change the myMail.HtmlBody to myMail.TextBody then it change the results were so ugly that i cant tell here. the same block of html code was thrown like as it it.

hence something else is required to solve this.

i hope you understand my point.

so can you suggest something.

raj
rshekhar21 is offline   Reply With Quote
Old 02-11-2013, 07:45 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Change this line:
Code:
strFeedMessage = Request.Form("Message")
To this:
Code:
strFeedMessage = Replace(Replace(Trim(Request.Form("Message"),vbCR,""),vbLF,"<br>")
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-12-2013, 11:06 AM   PM User | #8
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
well thanks sir,

however this did not run.

first when i change the "strFeedMessage = Request.Form("Message")" to "strFeedMessage = Replace(Replace(Trim(Request.Form("Message"),vbCR,""),vbLF,"<br>")"

i got an error message

"Microsoft VBScript compilation error '800a03ee'

Expected ')'

/tst/cu.asp, line 17

strFeedMessage = Replace(Replace(Trim(Request.Form("Message"),vbCR,""),vbLF,"<br>")
-----------------------------------------------------------------------------------^"

i then put one more closing bracket ')' at the end of the above line of code and tried again then i got this error

"Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Trim'

/tst/cu.asp, line 17
"

i guess something is wrong with the code itself.

please suggest.

thanks
rshekhar21 is offline   Reply With Quote
Old 02-12-2013, 10:35 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Sorry.

Code:
strFeedMessage = Replace(Replace(Trim(Request.Form("Message")),vbCR,""),vbLF,"<br>")
You need one ) to close the Request.Form( and another to close the Trim( and they go one right after the other.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-13-2013, 02:55 PM   PM User | #10
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
Resolved



well thanks sir,

you have really helped me a lot.

anyhow, for now my requirements are over. if i need to know anything more i will post here.

thanks again

Raj Shekhar

rshekhar21 is offline   Reply With Quote
Old 02-18-2013, 06:03 PM   PM User | #11
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
Question Captcha

sir, with your help i have create a well to do script for my contact us form.

however there is one more thing i wanted to add in my form. that is the captcha. how do i add a captcha to my form so that any form submission pass through the anti spam guideline and does not goes into junk mails.

is there any script available for it or any asp code is required to create that. please help me to understand this functionality. i will be again great-full to you.

my asp form script is mentioned above posts.

raj
rshekhar21 is offline   Reply With Quote
Old 02-19-2013, 03:35 AM   PM User | #12
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Google for it: "asp captcha"

I have my own code for it, but it requires an ActiveX component (see http://www.aspjpeg.com) which is not free.

But I have seen free ones. Many years ago. I would bet google can find them.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-23-2013, 05:48 PM   PM User | #13
rshekhar21
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
rshekhar21 is an unknown quantity at this point
asp date and time stamp

sir, thanks for helping me so far.

however one more thing i need to ask from you. with the current asp script i am able to send auto response and get the data append in the csv file. which i further pull with my excel to update the data.

i need to add one more variable in that array which gives the date and time stamp or may be two separate variables for date and time of the form submitter.

as a temporarily arrangement i have added an hidden input field with a java script code for the date and time, but the results are different at times, so i am planing to seek this help from you, that is to say let asp script does this trick for me. the only condition is that i need the current date & time of the senders system or the time should be Indian standard time in the format dd/mm/yyyy, 12:00:am/pm. please arrange this code for me. please refer my above asp script for the answer.

thanks a lot

raj
rshekhar21 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 AM.


Advertisement
Log in to turn off these ads.