.net/c#表格可以邮寄并张贴到网页上? [英] .net/c# form that will mail AND post to a webpage?

查看:102
本文介绍了.net/c#表格可以邮寄并张贴到网页上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Fairley刚接触过".net/C#",就像我从第一本书开始就是1/2一样.我有一个小型企业,有一个我创建的网站.我在理解aspx表格邮件方面获得了一些帮助,它们运作良好.但是,我的网站托管在Godaddy上,看来我们至少有一位客户填写了我们的联系表并点击发送",但它从未到达.在不更改任何代码的情况下,我们收到了许多其他邮件.

我的问题是这个.
有没有一种方法可以将代码添加到我的表单邮件中,以便当他们点击发送时,他们发送的电子邮件也会与信息一起发布/保存/或创建到新的网页上.这样是否应该再次发生这种情况,我可以去那里查看帖子并至少到达那里的联系信息?


预先谢谢您,

这是表格上的代码.我需要的只是将已收集的数据通过.txt .xml .aspx或我可以查看的任何内容发布到服务器上.



使用系统;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.ComponentModel;
使用System.Drawing;
使用System.Web.SessionState;
使用System.Xml;
使用System.IO;
使用System.Net.Mail;

公共局部类联系人:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{

}

私有void HTMLemailConf()
{
字符串serverPath = @ Server.MapPath("/");
StreamReader sr =新的StreamReader(serverPath +"quoteemail.htm");
字符串mB = sr.ReadToEnd();

MailAddress to = new MailAddress("info@lastresortdj.com","Last Resort Web Form");
MailAddress from = new MailAddress("quote@lastresortdj.com");

//MailAddress bcc = new MailAddress("magicaljeremy@att.net");
字符串subj =(TBfname.Text);

如果(TBfname.Text =="){mB = mB.Replace("@ NAME @",& nbsp;"); } else {mB = mB.Replace("@ NAME @",TBfname.Text); }
如果(TBlname.Text =="){mB = mB.Replace("@ PHONE @",& nbsp;"); } else {mB = mB.Replace("@ PHONE @",TBlname.Text); }
如果(TBemail.Text =="){mB = mB.Replace("@ EMAIL @",& nbsp;"); } else {mB = mB.Replace("@ EMAIL @",TBemail.Text); }
如果(DDmonth.SelectedValue.ToString()=="){mB = mB.Replace("@ MONTH @",& nbsp;"); } else {mB = mB.Replace("@ MONTH @",DDmonth.SelectedValue.ToString()); }
如果(DDday.SelectedValue.ToString()=="){mB = mB.Replace("@ DAY @",& nbsp;"); } else {mB = mB.Replace("@ DAY @",DDday.SelectedValue.ToString()); }
如果(DDyear.SelectedValue.ToString()=="){mB = mB.Replace("@ YEAR @",& nbsp;"); } else {mB = mB.Replace("@ YEAR @",DDyear.SelectedValue.ToString()); }
如果(DDcontacted.SelectedValue.ToString()=="){mB = mB.Replace("@ CONTACT @",& nbsp;"); } else {mB = mB.Replace("@ CONTACT @",DDcontacted.SelectedValue.ToString()); }
如果(quote.SelectedValue.ToString()=="){mB = mB.Replace("@ QUOTE @",& nbsp;"); } else {mB = mB.Replace("@ QUOTE @",quote.SelectedValue.ToString()); }
如果(Location.Text =="){mB = mB.Replace("@ LOCATION @",& nbsp;"); } else {mB = mB.Replace("@ LOCATION @",Location.Text); }
如果(TBmessage.Text =="){mB = mB.Replace("@ MESSAGE @",& nbsp;"); } else {mB = mB.Replace("@ MESSAGE @",TBmessage.Text); }



Response.Write(mB);

MailMessage mm =新的MailMessage(从,到);
mm.Body = mB;
mm.Subject =主题;
mm.IsBodyHtml = true;
//mm.Bcc.Add(bcc);

试试
{
SmtpClient客户端=新的SmtpClient();
client.Send(mm);
}
catch(ex ex例外)
{
Response.Write(ex.ToString());
}
}

私有void CustomValidator1_ServerValidate(对象源,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
如果(TBemail.Text == TBemail2.Text)
{
args.IsValid = true;
返回;
}
其他
{
args.IsValid = false;
}
}

受保护的无效btnPanel1_Click1(对象发送者,EventArgs e)
{
如果(Page.IsValid)
{
HTMLemailConf();
Response.Redirect("thankyou.html");
}
}

受保护的void CustomValidator1_ServerValidate1(对象源,ServerValidateEventArgs参数)
{
如果(TBemail.Text == TBemail2.Text){args.IsValid = true;返回; } else {args.IsValid = false; }
}
}

Im fairley new to ".net / C#" as in I''m 1/2 through my 1st book on it. I have a small business that has a website that i created. I received some help in understanding aspx form mailers and they work good. However my site is hosted at Godaddy and it appears that we have had at least one customer fill out our contact form and hit send, and it never arrived. Without changing any code we have received numourous other mails.

My Question is this.
Is there a way to add code to my form mailer so when they hit send, The email they send is also posted/saved/or created to a new web page with the info. That way should this happend again I can go there see the post and at least get there contact info?


Thank you in advance,

Here is a the code behind on the form. All i need is for it to take the data already gathered and post it somewhere to the server via .txt .xml .aspx or anything that i can view.



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Xml;
using System.IO;
using System.Net.Mail;

public partial class Contact : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

private void HTMLemailConf()
{
string serverPath = @Server.MapPath("/");
StreamReader sr = new StreamReader(serverPath + "quoteemail.htm");
string mB = sr.ReadToEnd();

MailAddress to = new MailAddress("info@lastresortdj.com", "Last Resort Web Form");
MailAddress from = new MailAddress("quote@lastresortdj.com");

//MailAddress bcc = new MailAddress("magicaljeremy@att.net");
string subj = (TBfname.Text);

if (TBfname.Text == "") { mB = mB.Replace("@NAME@", " "); } else { mB = mB.Replace("@NAME@", TBfname.Text); }
if (TBlname.Text == "") { mB = mB.Replace("@PHONE@", " "); } else { mB = mB.Replace("@PHONE@", TBlname.Text); }
if (TBemail.Text == "") { mB = mB.Replace("@EMAIL@", " "); } else { mB = mB.Replace("@EMAIL@", TBemail.Text); }
if (DDmonth.SelectedValue.ToString() == "") { mB = mB.Replace("@MONTH@", " "); } else { mB = mB.Replace("@MONTH@", DDmonth.SelectedValue.ToString()); }
if (DDday.SelectedValue.ToString() == "") { mB = mB.Replace("@DAY@", " "); } else { mB = mB.Replace("@DAY@", DDday.SelectedValue.ToString()); }
if (DDyear.SelectedValue.ToString() == "") { mB = mB.Replace("@YEAR@", " "); } else { mB = mB.Replace("@YEAR@", DDyear.SelectedValue.ToString()); }
if (DDcontacted.SelectedValue.ToString() == "") { mB = mB.Replace("@CONTACT@", " "); } else { mB = mB.Replace("@CONTACT@", DDcontacted.SelectedValue.ToString()); }
if (quote.SelectedValue.ToString() == "") { mB = mB.Replace("@QUOTE@", " "); } else { mB = mB.Replace("@QUOTE@", quote.SelectedValue.ToString()); }
if (Location.Text == "") { mB = mB.Replace("@LOCATION@", " "); } else { mB = mB.Replace("@LOCATION@", Location.Text); }
if (TBmessage.Text == "") { mB = mB.Replace("@MESSAGE@", " "); } else { mB = mB.Replace("@MESSAGE@", TBmessage.Text); }



Response.Write(mB);

MailMessage mm = new MailMessage(from, to);
mm.Body = mB;
mm.Subject = subj;
mm.IsBodyHtml = true;
//mm.Bcc.Add(bcc);

try
{
SmtpClient client = new SmtpClient();
client.Send(mm);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}

private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if (TBemail.Text == TBemail2.Text)
{
args.IsValid = true;
return;
}
else
{
args.IsValid = false;
}
}

protected void btnPanel1_Click1(object sender, EventArgs e)
{
if (Page.IsValid)
{
HTMLemailConf();
Response.Redirect("thankyou.html");
}
}

protected void CustomValidator1_ServerValidate1(object source, ServerValidateEventArgs args)
{
if (TBemail.Text == TBemail2.Text) { args.IsValid = true; return; } else { args.IsValid = false; }
}
}

推荐答案

嘿,

您可以将表单中填写的信息存储在数据源(数据库,xml文件或其他文件)中,并在Web表单上显示数据库的内容.我不知道您是否有权访问数据库服务器,但是使用XML文件应该是一个相当简单的解决方案.看看使用C#进行对象序列化 [
Hey there,

You can store the information filled in the form in a datasource (database, xml file or whatever), and display the database''s content on a webform. I don''t know if you have access to database server, but using an XML file should be a fairly easy solution. Take a peek at Object Serialization using C#[^] which should help you a lot!

Good luck,

Eduard


这篇关于.net/c#表格可以邮寄并张贴到网页上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆