发送邮件联系我们页面 [英] Send mail for Contact Us page
本文介绍了发送邮件联系我们页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好先生,
我只是想创建一个网站,我在联系我们页面时发送邮件有问题。
我的页面如下:
姓名:你的名字
年龄:你的年龄
性别:你的性别
手机:手机
电子邮件ID:您的邮件
描述:您的问题
提交
我希望当有人点击提交按钮填写所有信息时,所有信息都应该发送到我的邮件ID。请尽快帮助我。
Hello Sir,
I just try to make a website and i got problem to send mail in contact us page.
My page is as follows :
Name : your name
Age : your age
Sex : your sex
Mobile : mobile
Email Id : your mailid
Description : your question
Submit
I want when someone click on submit button by filling all infos, all the information should send to my mail id. Please help me for this asap.
推荐答案
这篇文章可以帮到你
使用ASP.NET和C#发送邮件/联系表单 [ ^ ]
This article may help you
Send Mail / Contact Form using ASP.NET and C#[^]
试试这个.. :)
.aspx页面...... :)
Try this..:)
.aspx page...:)
<div>
<table>
<tr>
<td>
Your name:
</td>
<td>
<asp:TextBox ID="YourName" runat="server" Width="250px" />
</td>
</tr>
<tr>
<td>
Your age:
</td>
<td>
<asp:TextBox ID="YourAge" runat="server" Width="250px" />
</td>
</tr>
<tr>
<td>
Gender:
</td>
<td>
<asp:TextBox ID="txtGender" runat="server" Width="250px" />
</td>
</tr>
<tr>
<td>
Mobile:
</td>
<td>
<asp:TextBox ID="txtMobile" runat="server" />
</td>
</tr>
<tr>
<td>
EmailID
</td>
<td>
<asp:TextBox ID="txtEmailID" runat="server" />
</td>
</tr>
<tr>
<td>
Description:
</td>
<td>
<asp:TextBox ID="txtdescrition" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" Text="Send"
OnClick="Button1_Click" ValidationGroup="save" />
</td>
</tr>
<tr>
<td colspan="2"><asp:label id="DisplayMessage" runat="server" visible="false" xmlns:asp="#unknown" /></td>
</tr>
</table>
</div>
.aspx.cs page ... :)
.aspx.cs page...:)
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "Your email address";
// any address where the email will be sending
var toAddress = txtEmailID.Text.ToString();
//Password of your gmail address
const string fromPassword = "Password";
// Passing the values and make a email formate to display
string subject = txtdescrition.Text.ToString();
string body = "From: " + YourName.Text + "\n";
body += "Email: " + txtEmailID.Text + "\n";
body += "Subject: " + txtdescrition.Text + "\n";
body += "Mobile: \n" + txtMobile.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void Button1_Click(object sender, EventArgs e)
{
SendMail();
try
{
//here on button click what will done
SendMail();
DisplayMessage.Text = "Your Comments after sending the mail";
DisplayMessage.Visible = true;
YourSubject.Text = "";
txtEmail.Text = "";
YourName.Text = "";
Comments.Text = "";
}
catch (Exception) { }
}
这篇关于发送邮件联系我们页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文