简体   繁体   English

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

[英]ASP.net send email from HTML form

Below is my HTML form. 下面是我的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>

I need to email this content when user clicks the submit button. 当用户单击提交按钮时,我需要通过电子邮件发送此内容。 i saved this file as .html. 我将此文件另存为.html。 I'm new to asp.net. 我是asp.net的新手。 Please help me how to send email. 请帮助我如何发送电子邮件。 From email id will be a fixed one (Ex: test@domainname.com). 电子邮件ID中的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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM