Reputation: 55
When I fill in the contact form the page reloads and no mail get sent to the receiver email.
But i also want when the user presses the send button, and an email get sent to the receiver, that there a messagebox pops with text like: "a copy was sended to your email"
The ASP.NET vb code behind
Imports System.Net Imports System.Net.Mail Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) Dim Message As MailMessage = New MailMessage() Dim Smtp As New SmtpClient() Dim SmtpUser As New System.Net.NetworkCredential() Message.From = New MailAddress("[email protected]", "Van voorbeeld") Message.To.Add(New MailAddress("[email protected]", "Naar voorbeeld")) Message.IsBodyHtml = False Message.Subject = "Nefsani Contact Form" Message.Body = "Email: " & Qemail.Text & Environment.NewLine & "Phone: " & QTel.Text & Environment.NewLine & "Question: " & Qmessage.Text SmtpUser.UserName = "[email protected]" SmtpUser.Password = "Password" Smtp.UseDefaultCredentials = False Smtp.Credentials = SmtpUser Smtp.Host = "smtp.mijnhostingpartner.nl" Smtp.DeliveryMethod = SmtpDeliveryMethod.Network Smtp.Send(Message) End Sub
code in aspx file
<div class="col-md-3 col-sm-6 footer-widget">
<h4>Contacteer mij</h4>
<ul>
<asp:TextBox ID="QFullname" class="form-control" placeholder="Naam + Voornaam" alt="Naam + Voornaam " runat="server"></asp:TextBox><br >
<asp:TextBox ID="QTel" class="form-control" placeholder="Telefoonnummer" alt="Telefoonnummer" runat="server"></asp:TextBox> <br >
<asp:TextBox ID="Qemail" class="form-control" placeholder="Email adres" alt="Email adres" runat="server"></asp:TextBox> <br >
</ul>
</div>
<div class="col-md-3 col-sm-6 footer-widget">
<div class="contact-footer">
<ul>
<asp:TextBox style="margin-top:52px" id="Qmessage" class="form-control" rows="4" TextMode="multiline" placeholder="Schrijf hier uw bericht." alt="Schrijf hier uw bericht." runat="server" />
<br><br/>
<asp:Button ID="btnSend" style="margin-top:-40px" class="btn btn-primary" runat="server" Text="Verzend" />
<asp:Label id="lblMessage" runat="server"></asp:Label>
</ul>
</div>`enter code here`
</div>
Upvotes: 1
Views: 450
Reputation: 15968
The reason you're getting nothing is that your button isn't tied to your click function. You either have to add an onclick to the button or you have to add a handles event to your function.
<asp:Button ID="btnSend" style="margin-top:-40px" class="btn btn-primary" runat="server" Text="Verzend" onclick="btnSend_Click" />
or
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) handles btnSend.Click
as for displaying the message at the bottom of your click handler put:
lblMessage.Text = "a copy was sended to your email"
Upvotes: 0