4 Replies Latest reply on May 13, 2010 12:30 PM by jonboy0000

    asp.net - form processing/emailing entries to my address

    jonboy0000 Level 1

      I'm looking for a good tutorial or a brief explanation - how to create a form using asp.net that would send the entry right to my email address when submitted.

       

      Before yesterday I've never used asp.net and don't know any other server-side scripting, but went through a long tutorial. I can read it, to a degree, but not write yet. any help, much appreciated.

        • 1. Re: asp.net - form processing/emailing entries to my address
          bregent Most Valuable Participant

          Hi Jon, why did you decide to use ASP.net rather than PHP?  PHP is a much simpler language for the casual user. Most .net languages are geared more towards experienced programmers. In any case, you should be able to find a ASP.net script for any particular languages by searching the web for asp.net form mail script.

          • 2. Re: asp.net - form processing/emailing entries to my address
            jonboy0000 Level 1

            The server I use is run by a seperate department at work, and actually doesn't support php - which I heard is rare. The administrator said he could install whatever it is he'd need to use PHP, but he suggested I try out asp.net.

             

            For this site, especially since I'm being paid for it - I don't mind experimenting with asp.net. I want to learn.
            For my personal site, I'll be using PHP...

             

            Thanks for the advice though - I found a couple tutorials already

            • 3. Re: asp.net - form processing/emailing entries to my address
              jonboy0000 Level 1

              <% @Import Namespace="System.Web.Mail" %>
              <script language="vb" runat="server">

              Sub btnSendFeedback_Click(sender as Object, e as EventArgs)

                'Create an instance of the MailMessage class
                Dim objMM as New MailMessage()

                'Set the properties - send the email to the person who filled out the
                'feedback form.
                objMM.To = "webmaster@yoursite.com"
                objMM.From = txtEmail.Text

                'If you want to CC this email to someone else, uncomment the line below
                'objMM.Cc = "someone@someaddress.com"

                'If you want to BCC this email to someone else, uncomment the line below
                'objMM.Bcc = "someone@someaddress.com"

                'Send the email in text format
                objMM.BodyFormat = MailFormat.Text
                '(to send HTML format, change MailFormat.Text to MailFormat.Html)

                'Set the priority - options are High, Low, and Normal
                objMM.Priority = MailPriority.Normal

                'Set the subject
                objMM.Subject = "4GuysFromRolla.com - Feedback"

                'Set the body
                objMM.Body = "At " + DateTime.Now + " feedback was sent from an ASP.NET " & _
                             "Web page.  Below you will find the feedback message " & _
                             "send by " & txtName.Text & "." & vbCrLf & vbCrLf & _
                             "---------------------------------------" & vbCrLf & vbCrLf & _
                             txtMessage.Text & vbCrLf

               
                'Specify to use the default Smtp Server
                SmtpMail.SmtpServer = ""
               
                'Now, to send the message, use the Send method of the SmtpMail class
                SmtpMail.Send(objMM)


                panelSendEmail.Visible = false
                panelMailSent.Visible = true
              End Sub

              </script>

              <html>
              <body>
                <asp:panel id="panelSendEmail" runat="server">
                  <form runat="server">
                    <h2>We are interested in your feedback!  Please enter the following
                    requested information below to send us your comments.</h2>

                    <b>Your Name:</b>
                    <asp:textbox id="txtName" runat="server" />
                    <br>

                    <b>Your Email Address:</b>
                    <asp:textbox id="txtEmail" runat="server" />
                    <p>

                    <b>Your Message:</b><br>
                    <asp:textbox id="txtMessage" TextMode="MultiLine"
                                    Columns="40" Rows="10" runat="server" />
                    <p>

                    <asp:button runat="server" id="btnSendFeedback" Text="Send Feedback!"
                                OnClick="btnSendFeedback_Click" />
                  </form>
                </asp:panel>


                <asp:panel id="panelMailSent" runat="server" Visible="False">
                  An email has been sent to the email address you specified.  Thanks!
                </asp:panel>
              </body>
              </html>

               

              Any idea why this isn't working? I get an error - "Server Error in '/' Application" runtime error.

              • 4. Re: asp.net - form processing/emailing entries to my address
                jonboy0000 Level 1

                It was because it was for asp.net 1.0, not 2.0 and beyond.

                http://articles.sitepoint.com/article/sending-web-email-asp-net - a good tutorial/sample script for 2.0.