How can I create a contact form to send mail on button click in asp and C#? Below is the code from the contact form that I have, when the button (#Button1) is clicked I want to submit the form to email: "[email protected]" but without refreshing the page, only to send the form and toggle a div (#submit)?
<form id="form1" runat="server">
<div class="input-boxes">
<div class="left-inputs">
<div class="input-place required first" style="margin-top: 0px !important;">
<input name="name" id="name" type="text" placeholder=" " runat="server" required>
<label for="name">Full Name *</label>
</div>
<div class="input-place required second" style="margin-bottom: 0px !important;">
<input name="txtemail" id="txtemail" type="email" placeholder=" " runat="server" required>
<label for="email">E-mail *</label>
</div>
</div>
<div class="right-inputs">
<textarea name="message" id="message" type="text" placeholder=" " runat="server" required></textarea>
<label for="message">How can we help you? *</label>
</div>
</div>
<div class="first-part-end">
<div class="slider">
<div class="slider-circle"></div>
</div>
<p class="more-options">Show more options</p>
</div>
<div class="input-boxes additional">
<div class="left-inputs">
<div class="input-place">
<input name="pany" id="pany" type="text" placeholder=" " runat="server">
<label for="pany">Company Name</label>
</div>
<div class="input-place" >
<input name="phone" id="phone" type="tel" runat="server">
<input type="hidden" name="country" id="country" value="" runat="server">
</div>
<script>
$("#phone").intlTelInput();
</script>
</div>
<div class="right-inputs">
<div class="input-place" style="height: 60px !important;">
<p class="budget-input">Your budget:
<span id="demo"></span></p>
<input name="budget" type="range" min="0" max="5" value="0" step="0" class="budget-slider" id="budgetRange" list="steplist" runat="server">
<datalist id="steplist">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</datalist>
</div>
<div class="input-place" style="display: initial !important;">
<p class="checkbox-input">I'm interested in: </p>
<div class="check_all">
<label class="container">Web Design
<input name="web-design" type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Web Development
<asp:CheckBox ID="CheckBox1" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">App Design
<asp:CheckBox ID="CheckBox2" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">App Prototyping
<asp:CheckBox ID="CheckBox3" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">E-Commerce
<asp:CheckBox ID="CheckBox4" runat="server" />
<span class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
<div class="send-button">
<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" />
</div>
</form>
Here is the div that need to be toggled when the button is cliicked:
<div class="form-send" id="submit">
<div class="dialog">
<img src="Content/icons/success.svg">
<h2>Thanks for reaching us!</h2>
<p>We appreciate you contacting us. Our team will get back to you shortly.</p>
<div class="close-confirmation">Close</div>
</div>
</div>
How can I create a contact form to send mail on button click in asp and C#? Below is the code from the contact form that I have, when the button (#Button1) is clicked I want to submit the form to email: "[email protected]" but without refreshing the page, only to send the form and toggle a div (#submit)?
<form id="form1" runat="server">
<div class="input-boxes">
<div class="left-inputs">
<div class="input-place required first" style="margin-top: 0px !important;">
<input name="name" id="name" type="text" placeholder=" " runat="server" required>
<label for="name">Full Name *</label>
</div>
<div class="input-place required second" style="margin-bottom: 0px !important;">
<input name="txtemail" id="txtemail" type="email" placeholder=" " runat="server" required>
<label for="email">E-mail *</label>
</div>
</div>
<div class="right-inputs">
<textarea name="message" id="message" type="text" placeholder=" " runat="server" required></textarea>
<label for="message">How can we help you? *</label>
</div>
</div>
<div class="first-part-end">
<div class="slider">
<div class="slider-circle"></div>
</div>
<p class="more-options">Show more options</p>
</div>
<div class="input-boxes additional">
<div class="left-inputs">
<div class="input-place">
<input name="pany" id="pany" type="text" placeholder=" " runat="server">
<label for="pany">Company Name</label>
</div>
<div class="input-place" >
<input name="phone" id="phone" type="tel" runat="server">
<input type="hidden" name="country" id="country" value="" runat="server">
</div>
<script>
$("#phone").intlTelInput();
</script>
</div>
<div class="right-inputs">
<div class="input-place" style="height: 60px !important;">
<p class="budget-input">Your budget:
<span id="demo"></span></p>
<input name="budget" type="range" min="0" max="5" value="0" step="0" class="budget-slider" id="budgetRange" list="steplist" runat="server">
<datalist id="steplist">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</datalist>
</div>
<div class="input-place" style="display: initial !important;">
<p class="checkbox-input">I'm interested in: </p>
<div class="check_all">
<label class="container">Web Design
<input name="web-design" type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Web Development
<asp:CheckBox ID="CheckBox1" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">App Design
<asp:CheckBox ID="CheckBox2" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">App Prototyping
<asp:CheckBox ID="CheckBox3" runat="server" />
<span class="checkmark"></span>
</label>
<label class="container">E-Commerce
<asp:CheckBox ID="CheckBox4" runat="server" />
<span class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
<div class="send-button">
<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" />
</div>
</form>
Here is the div that need to be toggled when the button is cliicked:
<div class="form-send" id="submit">
<div class="dialog">
<img src="Content/icons/success.svg">
<h2>Thanks for reaching us!</h2>
<p>We appreciate you contacting us. Our team will get back to you shortly.</p>
<div class="close-confirmation">Close</div>
</div>
</div>
Share
Improve this question
asked Jul 8, 2018 at 18:06
Victor GavrilovicVictor Gavrilovic
612 silver badges9 bronze badges
3
- aspnet.4guysfromrolla./articles/072606-1.aspx, systemnetmail./default.aspx – wazz Commented Jul 9, 2018 at 0:37
- You should use Ajax for posting. – Noor All Safaet Commented Jul 9, 2018 at 0:53
- Are you using Master page of ASP.NET? – Noor All Safaet Commented Jul 9, 2018 at 0:57
1 Answer
Reset to default 3The server side code:
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "[email protected]";
// any address where the email will be sending
var toAddress = YourEmail.Text.ToString();
//Password of your gmail address
const string fromPassword = "Password";
// Passing the values and make a email formate to display
string subject = YourSubject.Text.ToString();
string body = "From: " + YourName.Text + "\n";
body += "Email: " + YourEmail.Text + "\n";
body += "Subject: " + YourSubject.Text + "\n";
body += "Question: \n" + Comments.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//here on button click what will done
SendMail();
DisplayMessage.Text = "Your Comments after sending the mail";
DisplayMessage.Visible = true;
YourSubject.Text = "";
YourEmail.Text = "";
YourName.Text = "";
Comments.Text = "";
}
catch (Exception) { }
}
on Button submit you can perform actions open confirmation dialog box.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745449715a4628212.html
评论列表(0条)