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

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.

html:
<div>
<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;"
width="100%">
<tr>
<td style="width: 155px">
your address</td>
<td>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 155px">
your titr</td>
<td>
<asp:TextBox ID="txtxtitr" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 155px">
send to</td>
<td>
<asp:DropDownList ID="drdnsend" runat="server" Font-Names="Tahoma">
<asp:ListItem Value="info@mydomain.com">email1</asp:ListItem>
<asp:ListItem Value="admin@mydomain.com">email2</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 155px" valign="top">
body message</td>
<td>
<asp:TextBox ID="txtbody" runat="server" Height="223px" TextMode="MultiLine"
Width="540px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 155px">
<asp:Button ID="btnsend" runat="server" BackColor="#424242" BorderStyle="None"
Font-Names="Tahoma" Font-Size="11pt" ForeColor="White" Text="send" />
</td>
<td>
</td>
</tr>
</table>
</div>


codebehind:

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


Thanks
Posted
Updated 20-Nov-10 0:29am
v6
Comments
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:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

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
 
Share this answer
 
Comments
Henry Minute 24-Nov-10 11:46am    
Comment from OP: "This code does not work properly."
tanks.
This code does not work properly.
I want user to get his views.
What is the code for it
thank u all.
 
Share this answer
 
Comments
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?
hi.
Messages are sent, but the Inbox did not.
 
Share this answer
 

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