Hi all,
I’m a PHP developer now into ASP.NET using C#, i designed a form which when submitted sends an email to the administrator.as of i’m a newbie, i#m unable to understand the C# here. can anyone please help me out…
I’m now getting RELAY response from the SMTP when i set smtp server as localhost.
here’s my c# code, please do help me…
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;
namespace tc.conferencing._contact_us
{
public partial class conferencing_contactus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
SendMail();
}
private void SendMail()
{
MailMessage mail = new MailMessage();
mail.To = "xyz@gmail.com";
mail.From = "abc@gmail.com";
mail.Subject = "HI";
mail.Body = "Online Enquiry Test Form";
label.Text = "Please Wait...";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
label.Text = "Your Enquiry Has Been Submitted, We will Get Back to you sooner.";
}
}
}
here’s my .aspx page:
<tr><td class="main2"><strong>Enquiry Form</strong></td></tr>
<tr><td class="main2"></td></tr>
<tr><td class="main2">Please use the form below to fill in your details and a detailed information about your enquiry. One of our staff will be in touch with you as soon as possible.</td></tr>
<tr><td class="main2">Alternatively you may wish to telephone us directly, to do so please use the links on the left hand side to go to our branch details where we have telephone, fax and direct email addresses.</td></tr>
<tr><td class="main2"></td></tr>
<tr><td class="main2" valign="top">
<table cellpadding="0" cellspacing="5" width="100%" class="main2">
<tr><td align="right">Title</td><td align="left">
<asp:DropDownList class="ClassicTxtField" ID="Title" name="Title" runat="server" Height="18px" Width="58px">
<asp:ListItem Value="Mr."></asp:ListItem>
<asp:ListItem Value="Mrs."></asp:ListItem>
<asp:ListItem Value="Ms."></asp:ListItem>
<asp:ListItem Value="Miss."></asp:ListItem>
</asp:DropDownList>
</td></tr>
<tr><td align="right">First Name</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="FirstName" name="FirstName" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">Last Name</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="LastName" name="LastName" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">Address Line 1</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="AddressLine1" name="AddressLine1" runat="server" Height="18px" Width="214px"></asp:TextBox>
*</td></tr>
<tr><td align="right"></td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="AddressLine2" name="AddressLine2" runat="server" Height="18px" Width="214px"></asp:TextBox>
</td></tr>
<tr><td align="right">Town</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="Town" name="Town" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">Postcode</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="Postcode" name="Postcode" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">County</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="County" name="County" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">Country</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="Country" name="Country" runat="server" Height="18px" Width="154px"></asp:TextBox>
*</td></tr>
<tr><td align="right">Enquiry Subject Line</td><td align="left">
<asp:TextBox class="ClassicTxtField" ID="Subject" name="Subject" runat="server" Height="18px" Width="352px"></asp:TextBox>
*</td></tr>
<tr><td align="right" valign="top">Your Enquiry</td><td align="left" valign="top"><textarea runat="server" id="Message" class="ClassicTxtField" rows="15" cols="60" name="Message"></textarea>*</td></tr>
<tr><td align="right"></td><td align="left">
<asp:Button ID="Button" class="ClassicButton" runat="server" Height="18px" Text="Submit Your Enquiry"
Width="202px" onclick="Button_Click" />
</td></tr>
</table>
</td></tr>
</table>
i’m trying to show user a label ‘mail sent’ when button click event performed successfully, else an error message.
can anyone pls give me an idea how to proceed…
many thanks