0

I have an feedback form , which is having detailed fields like 1. Name , 2. Email , 3. Profession , 4. country , 5. Comments , I want all these details to be get in my email account when any guest gives his/her feedback ... these details should be email me in my email id on submit event.

Please provide me some suggestion and code to do this in asp.net C#

Rahul Prajapati
  • 202
  • 2
  • 9

2 Answers2

2

So lets say that on your ASP.NET form you have something like the following:

<asp:TextBox ID="txtName" runat="server" />
<asp:TextBox ID="txtEmail" runat="server" /> 
..
<asp:Button runat="server" ID="btnSendFeedback" OnClick="btnClick" Text="Send Feedback"/>

Then in the code-behind, handle the feedback button click:

protected void btnClick(object sender, EventArgs e)
{
    MailMessage message = new MailMessage();
    message.From = new MailAddress(txtEmail.Text);

    // this should be replaced with your address 

    message.To.Add(new MailAddress("youremailaddress@foo.bar.com"));

    message.Subject = "feedback";

    // this is the email content, eg comments, profession, country, etc
    message.Body = "Name: " + txtName.Text;  // add more fields...


    // finaly send the email:
    SmtpClient client = new SmtpClient();
    client.Send(message);

}

Also make sure you set up the web.config, like so (or something similar)

<system.net>
    <mailSettings>
      <smtp from="test@foo.com">
        <network host="yousmtpserver" port="25" userName="username" password="password" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

For more info, have a look at this:

skub
  • 2,266
  • 23
  • 33
0

One you have your form controls setup, you just have to build the email body and subject then send it to you.

UPDATE

Something like:

<asp:TextBox ID="txtName" runat="server" />
<asp:TextBox ID="txtEmail" runat="server" />
<asp:TextBox ID="txtComments" multiline="true" runat="server" />

Then on your form submit postback method, something like this to build up the email body:

StringBuilder sb = new StringBuilder();
sb.AppendLine("You have an email from " + txtName.Text);
sb.AppendLine("Their email is: " + txtEmail.Text);
sb.AppendLine("Comments: " + txtComments.Text);

Then set the sb.ToString() as your email body.

Here is an example that walks you through some of that process - http://www.daniweb.com/web-development/aspnet/threads/68369

shanabus
  • 12,989
  • 6
  • 52
  • 78
  • i have created my body and structure , but is it possible to take all these fields in my email id ??? i means these 5 fields which i have mentioned ???? is it possible to take all these details ???? – Rahul Prajapati Feb 19 '12 at 19:22
  • what do you mean take all these fields in my email id? I don't know what you mean by that. Does the update help? – shanabus Feb 19 '12 at 19:30