Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am currently building a website. I want to receive the contents submitted in Inquiry form of Contact-Us page. On submit click event of the inquiry form, the contents should be send to my email id. Please guide me.

Thanks in advance.
Posted

Yes you can easily send a mail. On submit click event handler, you need to write a logic for sending a mail. ASP.NET provides a very good API to support this.

Similar question is answered here
how to send email from asp.net using c#[^]
 
Share this answer
 
MailMessage msg = new MailMessage();

msg.From.Add(txtemail.Text);
msg.Subject = "Enquiry";
msg.Body = '"+txtenquiry.Text+"';

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 25;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential("Youremail@gmail.com", "yourpassword");
smtp.Send(msg);
 
Share this answer
 
v2
Add header File
using System.Net.Mail


Then on Sbmit Button Click...write the code

XML
protected void Button1_Click(object sender, EventArgs e)
    {
        string Name = Txtname.Text;
        string Email = Txtemail.Text;
        string Phone = Txtphone.Text;
        string Country = Txtcountry.Text;
        string Comments = Txtcomments.Text;

        MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress("youremail@gmail.com");
        Msg.To.Add("youremail@gmail.com");
        Msg.Subject = "Query";
        string body = " Name: " + Name + "<br/>";
        body += "Email: " + Email + "<br/>";
        body += "Phone : " + Phone + "<br/>";
        body += "Country: " + Country + "<br/>";
        body += "Comments: " + Comments + "<br/>";
        Msg.Body = body;
        Msg.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("youremail@gmail.com", "yourpassword");
        smtp.EnableSsl = true;
        smtp.Send(Msg);
        Response.Write("<script language='javascript'>alert('Your Query  is Submitted!!')</script>");
        Name = string.Empty;
        Phone = string.Empty;
        Email = string.Empty;
        Country = string.Empty;
        Comments = string.Empty;

    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900