Code at top of document :
<%@ Import Namespace="System.Web.Mail" %>
<script language="c#" runat="server">
private void btnSend_Click(object sender, System.EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To = "email@website.com";
msg.From = txtFrom.Text;
msg.Subject = "Site contact page.";
msg.Body = "Name: " + txtName.Text + "\n" + txtContent.Value;
lblStatus.Text = "Sending...";
SmtpMail.Send(msg);
lblStatus.Text = "Your e-mail was sent!";
}
</script>
Code for form embedded in document:
<form id="MailForm" method="post" runat="server">
<asp:Label ID="Label0" runat="server">Name: <span class="required">*</span>
</asp:Label>
<asp:TextBox ID="txtName"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator0" runat="server" ErrorMessage="Please enter your name." Width="200px"
Height="23px" ControlToValidate="txtName"></asp:RequiredFieldValidator><br />
<asp:Label ID="Label1" runat="server">E-mail: <span class="required">*</span>
</asp:Label>
<asp:TextBox ID="txtFrom"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="FromValidator1" runat="server" ErrorMessage="Please enter your e-mail address." Width="200px"
Height="23px" ControlToValidate="txtFrom"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="FromValidator2" runat="server" ErrorMessage="Please enter a valid e-mail address"
ControlToValidate="txtFrom" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)
*"></asp:RegularExpressionValidator>
<p>Message: <span class="required">*</span></p>
<textarea runat="server" id="txtContent" rows="7" cols="30"></textarea><br />
<asp:Button ID="btnSend" runat="server"
Text="Send" onclick="btnSend_Click"></asp:Button>
<asp:Label ID="lblStatus" runat="server">
</asp:Label>
</form>

New Topic/Question
Reply




MultiQuote





|