如何通过电子邮件接收以联系我们页面的查询表格提交的内容 [英] How to receive contents submitted in inquiry form of Contact Us page through email
本文介绍了如何通过电子邮件接收以联系我们页面的查询表格提交的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我目前正在建立一个网站。我想收到以联系我们页面的查询表格提交的内容。在提交查询表单的点击事件时,内容应发送到我的电子邮件ID。请指导我。
提前致谢。
Hello,
I am currently building a website. I want to receive the contents submitted in Inquiry form of Contact-Us page. On submit click event of the inquiry form, the contents should be send to my email id. Please guide me.
Thanks in advance.
推荐答案
是的,您可以轻松发送邮件。在提交单击事件处理程序时,您需要编写用于发送邮件的逻辑。 ASP.NET提供了一个非常好的API来支持这个。
类似的问题在这里得到解答
如何使用c#从asp.net发送电子邮件 [ ^ ]
Yes you can easily send a mail. On submit click event handler, you need to write a logic for sending a mail. ASP.NET provides a very good API to support this.
Similar question is answered here
how to send email from asp.net using c#[^]
MailMessage msg = new MailMessage();
msg.From.Add(txtemail.Text);
msg.Subject =查询;
msg.Body ='+ txtenquiry.Text +';
SmtpClient smtp =新的SmtpClient();
smtp.Host =smtp.gmail.com;
smtp.Port = 25;
smtp。 EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(Youremail@gmail.c om,你的密码);
smtp.Send(msg);
MailMessage msg = new MailMessage();
msg.From.Add(txtemail.Text);
msg.Subject = "Enquiry";
msg.Body = '"+txtenquiry.Text+"';
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 25;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential("Youremail@gmail.com", "yourpassword");
smtp.Send(msg);
使用System.Net添加头文件
。邮件
然后在Sbmit按钮点击...编写代码
Add header File
using System.Net.Mail
Then on Sbmit Button Click...write the code
protected void Button1_Click(object sender, EventArgs e)
{
string Name = Txtname.Text;
string Email = Txtemail.Text;
string Phone = Txtphone.Text;
string Country = Txtcountry.Text;
string Comments = Txtcomments.Text;
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("youremail@gmail.com");
Msg.To.Add("youremail@gmail.com");
Msg.Subject = "Query";
string body = " Name: " + Name + "<br/>";
body += "Email: " + Email + "<br/>";
body += "Phone : " + Phone + "<br/>";
body += "Country: " + Country + "<br/>";
body += "Comments: " + Comments + "<br/>";
Msg.Body = body;
Msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("youremail@gmail.com", "yourpassword");
smtp.EnableSsl = true;
smtp.Send(Msg);
Response.Write("<script language='javascript'>alert('Your Query is Submitted!!')</script>");
Name = string.Empty;
Phone = string.Empty;
Email = string.Empty;
Country = string.Empty;
Comments = string.Empty;
}
这篇关于如何通过电子邮件接收以联系我们页面的查询表格提交的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文