-
Oct 31st, 2006, 07:35 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] A simple contact form asp.net 2.0
This is a very basic contact form which can be used for any kind of website. Web form contains name, email, subject and message inputs. When visitor ckicks send button, script send all informatiom from contact form. Change only mail server and default email within the script.
Code:
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">
Sub Send2Mail (sender as Object, e as EventArgs)
Dim objMail as New MailMessage()
objMail.To = "TAREGET_EMAIL@ADRESS"
objMail.From = strEmail.Text
objMail.BodyFormat = MailFormat.Text
objMail.Priority = MailPriority.Normal
objMail.Subject = strSubject.Text
objMail.Body = "Name : " + strName.Text + vbNewLine + "Email : " + strEmail.text + vbnewLine + "Message : " + strYourMsg.text
SmtpMail.SmtpServer = "mail.YOUR_SMTP_SERVER.com"
SmtpMail.Send(objMail)
strMessage.Visible = true
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>How to send email</title>
</head>
<body>
<asp:panel id="strMessage" runat="server" Visible="False">
Thanks for your kind message ... </asp:panel>
<form runat="server">
<b>First Name:</b> <br/>
<asp:textbox id="strName" runat="server" />
<br><br>
<b>Email Address:</b><br/>
<asp:textbox id="strEmail" runat="server" />
<br><br>
<b>Subject:</b><br/>
<asp:textbox id="strSubject" runat="server" />
<br><br>
<b>Your Message</b><br/>
<asp:textbox id="strYourMsg" runat="server" Columns="45" Rows="10" TextMode="MultiLine" />
<br />
<asp:button runat="server" id="func" Text="Send Message"
OnClick="Send2Mail" />
</form>
</body>
</html>
-
Jan 13th, 2010, 04:19 PM
#2
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Hi, Thanks for the codes, very simple and useful...
I have changed the email address and also set SMTP to local host...
when trying it without debugging and filling the required fields, after pressing the submit button, it says that the message has been sent... bet I don't receive it in my email.
where do you think the problem might be?
Please help me... i'm really stuck here.
Thanks again
-
Jan 13th, 2010, 04:29 PM
#3
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Hi,
Did you try your localhost if it's working with another script or program?
thanks
-
Jan 13th, 2010, 06:07 PM
#4
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
well, to be honest i am very new to this subject... i haven't got any other script.. is that possible for you to provide me with a very simple script?
Thanks
-
Jan 19th, 2010, 05:18 AM
#5
Re: [RESOLVED] A simple contact form asp.net 2.0
Hey,
The problem here is likely to do with your SMTP configuration, not the code that has been provided. Are you sure you have configured the necessary settings to allow relaying of messages through your SMTP server?
Gary
-
Feb 5th, 2010, 12:56 AM
#6
Fanatic Member
Re: [RESOLVED] A simple contact form asp.net 2.0
can you illustrate step by step about configuring the necessary settings to allow relaying of messages through your SMTP server?
-
Feb 5th, 2010, 03:04 AM
#7
Re: [RESOLVED] A simple contact form asp.net 2.0
Hey,
This isn't really something that can be provided, as each SMTP server is different, and requires different authentication, etc. Whose SMTP Server are you trying to use? Your ISP? They should be able to provide you with the information that you need.
Gary
-
May 4th, 2011, 03:47 PM
#8
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
This form is nice, Thanks!
I need to add radio buttons and checkboxes to the form, I tried a few times and failed, kept getting a runtime error. Big newbie here so if someone could help, I would think it would be easy but I must be missing a detail somewhere.
Tim
-
May 5th, 2011, 12:57 AM
#9
Re: [RESOLVED] A simple contact form asp.net 2.0
Hello,
In order to help you we are going to need some more information.
Can you show the ASPX markup and code that you are using, as well as providing more information about the error that you are getting.
Gary
-
Jul 30th, 2011, 03:44 PM
#10
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Thank you for posting this. It works great.
Just one request...
Can you provide code to redirect to a different page?
-
Jul 30th, 2011, 03:51 PM
#11
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
nevermind, figured it out.
i put Response.Redirect("http://domain.com/page.html") below strmessage.visible.
Could you provide how to put the user's IP address at the bottom of the email?
Last edited by PokerMunkee; Jul 30th, 2011 at 04:12 PM.
-
Jul 31st, 2011, 12:24 AM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
vb Code:
Dim sClientIP As String = Request.ServerVariables("remote_addr")
This will get your client's IP info.
Last edited by met0555; Jul 31st, 2011 at 09:12 AM.
-
Jul 31st, 2011, 12:59 AM
#13
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Thanks!
In case anyone does this, I added this to the end of objMail.Body so it shows up in the email:
+ vbnewLine + "IP Address : " + sClientIP
-
Jul 31st, 2011, 07:19 AM
#14
Re: [RESOLVED] A simple contact form asp.net 2.0
The only thing that I would add is that vbnewline is an "old" way of doing it, you might want to think about using Environment.NewLine instead.
Gary
-
Oct 1st, 2011, 11:50 AM
#15
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
HI, After submitting form, we get this <aspanel id="strMessage" runat="server" Visible="False">
Thanks for your kind message ... </aspanel>
but It will not reset fields. is there any way after you submit the form to state Thank you message ONLY without the forms fields? how do you go about that?
-
Oct 1st, 2011, 01:16 PM
#16
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
If you are using my example, u can do it this way
write this after this strMessage.Visible = true
vb Code:
strEmail.Visible = false MailFormat.Visible = false strSubject.Visible = false strName.Visible = false strEmail.Visible = false
-
Oct 1st, 2011, 01:35 PM
#17
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
FYI, Congratulations! your sample is great. I love it.
I added the code suggested and unfortunately my page brakes and i get page not found. if i remove the code, it works fine.
Thanks
-
Oct 1st, 2011, 01:38 PM
#18
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Can you please post how u added the code.
thx
-
Oct 1st, 2011, 01:49 PM
#19
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Last edited by edusa2000; Oct 1st, 2011 at 10:24 PM.
Reason: want to remove records
-
Oct 1st, 2011, 02:31 PM
#20
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
ok, pls try this if still not working pks indicate on which line is the error.
Code:
strSubject.Visible = false
strName.Visible = false
strEmail.Visible = false
strYourMsg.Visible = false
thx
-
Oct 1st, 2011, 09:42 PM
#21
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Ok, I give up. Now it removes the text boxes, but the labels remain there. I am uploading the whole code
Last edited by edusa2000; Oct 1st, 2011 at 10:40 PM.
-
Oct 1st, 2011, 10:15 PM
#22
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
What i wud suggest, is that u redirect the user to a new page.
-
Oct 1st, 2011, 10:22 PM
#23
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Hi, as you can see, i already did it and it worked OK, buti rather see it in the same window. So you think this is it?
-
Oct 1st, 2011, 10:30 PM
#24
Thread Starter
Frenzied Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Change the plain text html label and replace it with <asp:label id="lblName" runat="server" /> .... then switch the visibility status to off.
-
Oct 1st, 2011, 10:41 PM
#25
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
Nah! It didn't work. well tahnks anyways buddy. I appreciate it
-
Oct 2nd, 2011, 03:29 AM
#26
Re: [RESOLVED] A simple contact form asp.net 2.0
Hello,
In order to best help you, we are going to need to see all the code that you are using. Is it possible that you can upload a zip file with the code in it, along with an explanation of exactly what it is that you are trying to do, as well as a description of what exactly isn't working?
Gary
-
Oct 2nd, 2011, 04:47 AM
#27
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
HI
Thank you. All i want is after i submit the form, to say thank you in the same page. I dont want to redirect. Here is the file
-
Oct 6th, 2011, 01:38 AM
#28
Re: [RESOLVED] A simple contact form asp.net 2.0
In which case, all you need to do is to set the Text property of a Label control on the same page once your post back to the server is finished.
Gary
-
Apr 24th, 2013, 11:44 PM
#29
New Member
Re: [RESOLVED] A simple contact form asp.net 2.0
thanks for your code, i think it so simple and useful for me and most of peoples
can you share some code like it
thanks!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|