Results 1 to 29 of 29

Thread: [RESOLVED] A simple contact form asp.net 2.0

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [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>

  2. #2
    New Member
    Join Date
    Jan 2010
    Posts
    2

    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

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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

  4. #4
    New Member
    Join Date
    Jan 2010
    Posts
    2

    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

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    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?

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  8. #8
    New Member
    Join Date
    May 2011
    Posts
    1

    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

  9. #9
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  10. #10
    New Member
    Join Date
    Jul 2011
    Posts
    3

    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?

  11. #11
    New Member
    Join Date
    Jul 2011
    Posts
    3

    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.

  12. #12

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [RESOLVED] A simple contact form asp.net 2.0

    vb Code:
    1. 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.

  13. #13
    New Member
    Join Date
    Jul 2011
    Posts
    3

    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

  14. #14
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  15. #15
    New Member
    Join Date
    Oct 2011
    Posts
    7

    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?

  16. #16

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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:
    1. strEmail.Visible = false
    2.  
    3.   MailFormat.Visible = false
    4.  
    5. strSubject.Visible = false
    6.  
    7.  strName.Visible = false
    8.  
    9. strEmail.Visible = false

  17. #17
    New Member
    Join Date
    Oct 2011
    Posts
    7

    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

  18. #18

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [RESOLVED] A simple contact form asp.net 2.0

    Can you please post how u added the code.

    thx

  19. #19
    New Member
    Join Date
    Oct 2011
    Posts
    7

    Re: [RESOLVED] A simple contact form asp.net 2.0

    Test no test
    Last edited by edusa2000; Oct 1st, 2011 at 10:24 PM. Reason: want to remove records

  20. #20

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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

  21. #21
    New Member
    Join Date
    Oct 2011
    Posts
    7

    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.

  22. #22

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [RESOLVED] A simple contact form asp.net 2.0

    What i wud suggest, is that u redirect the user to a new page.

  23. #23
    New Member
    Join Date
    Oct 2011
    Posts
    7

    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?

  24. #24

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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.

  25. #25
    New Member
    Join Date
    Oct 2011
    Posts
    7

    Re: [RESOLVED] A simple contact form asp.net 2.0

    Nah! It didn't work. well tahnks anyways buddy. I appreciate it

  26. #26
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  27. #27
    New Member
    Join Date
    Oct 2011
    Posts
    7

    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

  28. #28
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  29. #29
    New Member
    Join Date
    Apr 2013
    Posts
    6

    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
  •  



Click Here to Expand Forum to Full Width