当我填写联系表格时,页面重新加载,并且没有邮件被发送到收件人电子邮件。
但是我也希望当用户按下发送按钮,并且电子邮件被发送到接收者时,会在消息框中弹出如下文字:“已将副本发送到您的电子邮件”
背后的ASP.NET vb代码
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("sender@domain.be", "Van voorbeeld") Message.To.Add(New MailAddress("receiver@domain.be", "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 = "sender@domain.be" SmtpUser.Password = "Password" Smtp.UseDefaultCredentials = False Smtp.Credentials = SmtpUser Smtp.Host = "smtp.mijnhostingpartner.nl" Smtp.DeliveryMethod = SmtpDeliveryMethod.Network Smtp.Send(Message) End Sub
aspx文件中的代码
<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>
答案 0 :(得分:0)
您没有得到任何结果的原因是您的按钮与您的点击功能无关。您必须向按钮添加onclick,或者必须向函数添加handle事件。
<asp:Button ID="btnSend" style="margin-top:-40px" class="btn btn-primary" runat="server" Text="Verzend" onclick="btnSend_Click" />
或
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) handles btnSend.Click
在点击处理程序底部显示消息:
lblMessage.Text = "a copy was sended to your email"