我想添加我的代碼以通過C#發送電子郵件,但我的按鈕似乎不起作用。將C#添加到主頁面的網頁表格
HTML代碼:
<div style="text-align:center">
<p style="background-color: Yellow">if you have a video that you think should be here send it to us</p>Name:
<input type="text" id="Name" />Link:
<input type="text" id="Link" />
<br />Why you think this video should be here:
<br />
<textarea id="Why" rows="5" cols="50"></textarea>
<br />
<input type="submit" id="submit" name="submit" value="Send" style="height: 25px; width: 200px" />
</div>
aspx.cs代碼:
public partial class Videos : System.Web.UI.Page
{
public string Answer;
protected void Page_Load(object sender, EventArgs e)
{
Answer = "Email Sent2";
if (Request.Form["submit"] != null)
{
Answer = "Email Sent3";
string Name = Request.Form["Name"];
string Link = Request.Form["Link"];
string Why = Request.Form["Why"];
string body = "<div dir='ltr'>";
body += ("<h4>You got a new video idea from </h4>");
body += (Name);
body += ("<br />");
body += ("Link: " + Link);
body += ("<br />");
body += ("Reason: " + Why);
body += ("</div>");
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("MY EMAIL", "MY PASS"),
EnableSsl = true
};
System.Net.Mail.MailMessage mail1 = new System.Net.Mail.MailMessage();
mail1.Body = body;
mail1.From = new System.Net.Mail.MailAddress("MY EMAIL");
mail1.IsBodyHtml = true;
mail1.Subject = "Vidoe Idea By " + Name;
mail1.To.Add("MY EMAI");
client.Send(mail1);
Answer = "Email Sent";
}
}
我不知道爲什麼,但是當我按下按鈕沒有任何happend。 這裏有什麼問題?
你的鍵盤有問題嗎?嘗試使用asp:按鈕控件而不是HTML輸入 – geedubb
首先,調試代碼是因爲「我按下按鈕什麼都沒有發生」是用戶問題,而不是程序員問題..這裏介紹編程問題。其次,我不知道你是否可以使用webforms閱讀簡單的HTML,爲什麼不使用並在C#中將其作爲txtName.Text讀取,而不是Request.Form ?所以,調試你的代碼,搜索它不起作用的地方並再次告訴我們。 –
我打了我的代碼。它一直工作,直到if(Request.Form .. – KenigOri