Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.net从HTML表单发送电子邮件_C#_Asp.net_Html - Fatal编程技术网

C# ASP.net从HTML表单发送电子邮件

C# ASP.net从HTML表单发送电子邮件,c#,asp.net,html,C#,Asp.net,Html,下面是我的HTML表单 <div class="form-area"> <form role="form" method="post" action="" id="registerform"> <br style="clear:both"> <h3 style="margin-bottom: 25px; text-align: center;">Registration Form</h3> <div class="form-i

下面是我的HTML表单

<div class="form-area">  
<form role="form" method="post" action="" id="registerform">
<br style="clear:both">
<h3 style="margin-bottom: 25px; text-align: center;">Registration Form</h3>
<div class="form-inline">
<label class="radio">
<input value="property" type="radio" name="whatneed" checked="">&nbsp;&nbsp;&nbsp;Property Loan
</label>
&nbsp;&nbsp;&nbsp;<label class="radio">
<input value="automobile" type="radio" name="whatneed">&nbsp;&nbsp;&nbsp;Automobile Loan
</label>
</div>
<br>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="Your Budget" name="budget" required>
<span class="input-group-addon">.00</span>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="whenneed" placeholder="When are you planing to buy" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="location" placeholder="Location" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<textarea class="form-control" type="textarea" name="address" placeholder="Your Address" maxlength="140" rows="7"></textarea>                  
</div>
<div class="form-group">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="landline" placeholder="Landline Number" required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" required>
</div>
   <button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
</form>
</div>


登记表 物业贷款 汽车贷款
.00 提交表格
我需要在用户单击提交按钮时通过电子邮件发送此内容。我把这个文件保存为.html。我是asp.net新手。请帮助我如何发送电子邮件。来自电子邮件的id将是固定的(例如:test@domainname.com)

You can send email following way in ASP.NET.

 protected string SendEmail(string toAddress, string subject, string body)
   {
     string result = “Message Sent Successfully..!!”;
     string senderID = “SenderEmailID“;// use sender’s email id here..
     const string senderPassword = “Password“; // sender password here…
     try
     {
       SmtpClient smtp = new SmtpClient
       {
         Host = “smtp.gmail.com“, // smtp server address here…
         Port = 587,
         EnableSsl = true,
         DeliveryMethod = SmtpDeliveryMethod.Network,
         Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
          Timeout = 30000,
       };
       MailMessage message = new MailMessage(senderID, toAddress, subject, body);
       smtp.Send(message);
     }
     catch (Exception ex)
     {
       result = “Error sending email.!!!”;
     }
     return result;
    }