asp.net联系页面在本地运行,但不通过服务器运行

时间:2014-04-25 17:48:24

标签: c# asp.net contact-form

我有一个用于c#和asp.net页面的Windows服务器。

我的网站上有一个通用的联系表格,允许用户输入他们的姓名,电子邮件地址和评论。

问题是,它只能在本地运行。当我将文件上传到我的服务器时,它不是吗?

Doe有谁知道为什么?

这是我的contactform.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        MailMessage mailMsg = new MailMessage();

        mailMsg.From = new MailAddress(YourEmail.Text);

        mailMsg.To.Add("email@gmail.com");

        mailMsg.IsBodyHtml = true;

        mailMsg.Subject = "Customised Order!";

        mailMsg.Body = "Contact Details" + "<b>Name:</b>" + YourName.Text + " <br/> <b>Email - address :</b>" + YourEmail.Text + "<br/> <b>Comments :</b>" + Comments.Text;

        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

        mailMsg.Priority = MailPriority.Normal;

        smtp.Credentials = new System.Net.NetworkCredential("email@gmail.com", "mypassword");

        smtp.Timeout = 25000;

        smtp.EnableSsl = true;

        smtp.Send(mailMsg);

        DisplayMessage.Text = "Thank you. Your contact details and feed back has been submitted.";
    }
    catch (Exception)
    {
        DisplayMessage.Text = "Error: Did not send";
    }

0 个答案:

没有答案