Reputation: 21
Below is my HTML form.
<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=""> Property Loan
</label>
<label class="radio">
<input value="automobile" type="radio" name="whatneed"> 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. I'm new to asp.net. Please help me how to send email. From email id will be a fixed one (Ex: [email protected]).
Upvotes: 1
Views: 2277
Reputation: 1554
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;
}
Upvotes: 2