Click here to Skip to main content
15,066,651 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I cant spell english, sorry.

I want an ASP.NET contact form, that allows the users to send us some mail.

This is part of our code, but no mail is sent.

<table border="0" cellpadding="0" cellspacing="0" dir="rtl" align="right"
style="font-family: tahoma; font-size: 13px; color: #424242; padding-right: 10px; padding-bottom: 4px; background-color: #FFFFFF;"
<td style="width: 155px">
your address</td>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<td style="width: 155px">
your titr</td>
<asp:TextBox ID="txtxtitr" runat="server"></asp:TextBox>
<td style="width: 155px">
send to</td>
<asp:DropDownList ID="drdnsend" runat="server" Font-Names="Tahoma">
<asp:ListItem Value="">email1</asp:ListItem>
<asp:ListItem Value="">email2</asp:ListItem>
<td style="width: 155px" valign="top">
body message</td>
<asp:TextBox ID="txtbody" runat="server" Height="223px" TextMode="MultiLine"
<td style="width: 155px">
<asp:Button ID="btnsend" runat="server" BackColor="#424242" BorderStyle="None"
Font-Names="Tahoma" Font-Size="11pt" ForeColor="White" Text="send" />


protected void btnsend_Click(object sender, EventArgs e)
   MailMessage mailmsg = new MailMessage();
   mailmsg.From = new MailAddress(txtfrom.Text);
   mailmsg.Subject = txtxtitr.Text;
   mailmsg.Body = txtbody.Text;
   mailmsg.IsBodyHtml = false;
   SmtpClient smtp = new SmtpClient();
   smtp.Host = ("ipaddress");

Updated 20-Nov-10 0:29am
Manfred Rudolf Bihy 20-Nov-10 6:29am
Edited for clarity. Added code blocks.
Brij 20-Nov-10 6:35am
Is your SmtpClient is properly configured?

It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
     <smtp from="">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
If needed, there are lots of article on this very site on how to send emails
Henry Minute 24-Nov-10 11:46am
Comment from OP: "This code does not work properly."
This code does not work properly.
I want user to get his views.
What is the code for it
thank u all.
Henry Minute 24-Nov-10 11:45am
"does not work properly" is very imprecise. What doesn't work? Does it throw an exception? Does it send to the wrong address? What?

Have you even bothtered to watch the video that Sandeep kindly linked to for you?
Messages are sent, but the Inbox did not.

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