ASP.NET
Sending email with your web page in ASP.NET
in your config file enter :
<customErrors mode="Off"/>
before : </system.web>
contact.aspx
<%@ Page Title="" Language="C#"MasterPageFile="~/site.master" AutoEventWireup="true"CodeFile="Contact.aspx.cs" Inherits="Contact" %>
<asp:Content ID="Content1"ContentPlaceHolderID="head" Runat="Server">
<styletype="text/css">
.style1
{
color: #596D8E;
}
</style>
</asp:Content>
<asp:Content ID="Content2"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
<div class="post">
<h2class="title">
Contact Us</h2>
<div class="entry">
<p>
<spanclass="style1"><strong>Telephone :</strong></span> +441633853205</p>
<p>
<spanclass="style1"><strong>Mobile :</strong></span> +447908861828</p>
<p>
<spanclass="style1"><strong>Email :</strong></span> admin@richiecreative.co.uk<br/>
</p>
<table border = "0" style="width: 409px">
<tr>
<asp:Label ID="Label1"runat="server" Text="Name*"></asp:Label><br/>
</td>
<td>
<asp:TextBoxID="txtName" runat="server" ValidationGroup ="contact"></asp:TextBox><br />
</td>
<tr>
<td>
<asp:LabelID="Label2" runat="server"Text="Subject*"></asp:Label><br />
</td>
</td>
</tr>
<tr>
<td>
<asp:LabelID="Label3" runat="server"Text="Email*"></asp:Label><br />
</td>
<td>
<asp:TextBoxID="txtEmail" runat="server"></asp:TextBox><br/>
<asp:RegularExpressionValidator id="valRegEx"runat="server"
ControlToValidate="txtEmail"
ErrorMessage="*InvalidEmail address."
display="dynamic">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"runat="server" ErrorMessage="*"
</td>
</tr>
<tr>
<td valign ="top" >
<asp:LabelID="Label4" runat="server"Text="Content*"></asp:Label>
</td>
<asp:TextBoxID="RichTextBox" runat="server" TextMode ="MultiLine"
Height="164px" Width="343px" ></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"runat="server" ErrorMessage="*"
</td>
</tr>
<tr>
<td> Upload</td>
<td>
<asp:FileUploadID="FileUpload1" runat="server" />
</tr>
<tr>
<td></td>
<td>
<asp:ButtonID="btnSend" runat="server" Text="Send"OnClick="btnSend_Click" />
</td>
<td></td>
<td>
<asp:LabelID="lblMessage" runat="server" Text="" ForeColor= "Green"></asp:Label>
</table>
</div>
</div>
</asp:Content>
----------------------------------------------------------------------------------------------------------------------------------
contact.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Contact : System.Web.UI.Page
{
protected voidPage_Load(object sender, EventArgs e)
{
{
SmtpClient smtpClient =new SmtpClient();
string msg = string.Empty;
try
{
message.Subject =txtSubject.Text;
message.IsBodyHtml =true;
message.Body ="Name: " + txtName.Text + "<br /><br />Email: "+ txtEmail.Text + "<br /><br />Content: " +RichTextBox.Text;
if (FileUpload1.HasFile)
{
System.Net.NetworkCredential crdPassword = newSystem.Net.NetworkCredential("youremailusername", "youremailpassword");
client.Credentials =crdPassword;
client.Send(message);
lblMessage.Text = msg;
}
catch (Exception ex)
{
lblMessage.Text =ex.Message;
}
}
}
No comments:
Post a Comment