Click to See Complete Forum and Search --> : [RESOLVED] A simple contact form asp.net 2.0
met0555
Oct 31st, 2006, 07:35 AM
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.
<%@ 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>
ehsanvar
Jan 13th, 2010, 04:19 PM
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
met0555
Jan 13th, 2010, 04:29 PM
Hi,
Did you try your localhost if it's working with another script or program?
thanks
ehsanvar
Jan 13th, 2010, 06:07 PM
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
gep13
Jan 19th, 2010, 05:18 AM
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
HowTo
Feb 5th, 2010, 12:56 AM
can you illustrate step by step about configuring the necessary settings to allow relaying of messages through your SMTP server?
gep13
Feb 5th, 2010, 03:04 AM
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
tychaos
May 4th, 2011, 04:47 PM
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
gep13
May 5th, 2011, 01:57 AM
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
PokerMunkee
Jul 30th, 2011, 04:44 PM
Thank you for posting this. It works great.
Just one request...
Can you provide code to redirect to a different page?
PokerMunkee
Jul 30th, 2011, 04:51 PM
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?
met0555
Jul 31st, 2011, 01:24 AM
Dim sClientIP As String = Request.ServerVariables("remote_addr")
This will get your client's IP info.
PokerMunkee
Jul 31st, 2011, 01:59 AM
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
gep13
Jul 31st, 2011, 08:19 AM
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
edusa2000
Oct 1st, 2011, 12:50 PM
HI, After submitting form, we get this <asp:panel id="strMessage" runat="server" Visible="False">
Thanks for your kind message ... </asp:panel>
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?
met0555
Oct 1st, 2011, 02:16 PM
If you are using my example, u can do it this way
write this after this strMessage.Visible = true
strEmail.Visible = false
MailFormat.Visible = false
strSubject.Visible = false
strName.Visible = false
strEmail.Visible = false
edusa2000
Oct 1st, 2011, 02:35 PM
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
met0555
Oct 1st, 2011, 02:38 PM
Can you please post how u added the code.
thx
edusa2000
Oct 1st, 2011, 02:49 PM
Test no test
met0555
Oct 1st, 2011, 03:31 PM
ok, pls try this if still not working pks indicate on which line is the error.
strSubject.Visible = false
strName.Visible = false
strEmail.Visible = false
strYourMsg.Visible = false
thx
edusa2000
Oct 1st, 2011, 10:42 PM
Ok, I give up. Now it removes the text boxes, but the labels remain there. I am uploading the whole code
met0555
Oct 1st, 2011, 11:15 PM
What i wud suggest, is that u redirect the user to a new page.
edusa2000
Oct 1st, 2011, 11:22 PM
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?
met0555
Oct 1st, 2011, 11:30 PM
Change the plain text html label and replace it with <asp:label id="lblName" runat="server" /> .... then switch the visibility status to off.
edusa2000
Oct 1st, 2011, 11:41 PM
Nah! It didn't work. well tahnks anyways buddy. I appreciate it
gep13
Oct 2nd, 2011, 04:29 AM
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
edusa2000
Oct 2nd, 2011, 05:47 AM
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 (http://www.webandconsulting.com/mail.zip)
gep13
Oct 6th, 2011, 02:38 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.