Hi i'm new to asp.net & i'm developing an enquiry form for a website in asp.net 2003 which contains the foll fields:

Name:
Email id:
Message:
Submit

Submit is a button & on clicking it all the information entered in the above fields should be directed to the company email id. I've got a code from the net but it is not working. Pls Help me. Thanks

try using following code,

add the namespaces,

using System.Web.Mail;
using System.Web.SessionState;
using System.ComponentModel;

modify the following code as per your convenience.

#region Code to send emails automatically
        //code for sending mail to Admin



        try
        {
            // Create a new blank MailMessage
            MailMessage email = new MailMessage();


            // Set the properties of the MailMessage to the
            // values on the form
            email.BodyFormat = MailFormat.Html;
            email.From = "email of the sender."
            email.To = "Email of the recipient"

            email.Subject = "Thank You";
            email.Body = "You can add as many lines as you want in body. just need to use following method.";
            email.Body += "add more lines like this";
            email.Body += " <br>Test line 1";
            email.Body += "Test Line 2";
            email.Body += "Thank You <br><br>";
            email.Body += "Regards,<br>";

            // Set the SMTP server and send the email
            SmtpMail.SmtpServer = "your smtp server's name";
            SmtpMail.Send(email);


            
        }
        catch (Exception ex)
        {
            // Print a much less friendly message informing the 
            // user about the exception that was risen

        }

hope this helps.

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.