无法在 asp.net vb 网站中发送电子邮件
can't send email in asp.net vb website
当我填写联系表格时,页面会重新加载,并且没有邮件发送到收件人邮箱。
但我也希望当用户按下发送按钮时,一封电子邮件被发送到收件人,那里会弹出一个消息框,其中包含如下文本:"a copy was sended to your email"
ASP.NETvb背后的代码
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>
你什么也没得到的原因是你的按钮没有绑定到你的点击功能。您要么必须向按钮添加一个 onclick,要么必须向您的函数添加一个 handles 事件。
<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"
当我填写联系表格时,页面会重新加载,并且没有邮件发送到收件人邮箱。
但我也希望当用户按下发送按钮时,一封电子邮件被发送到收件人,那里会弹出一个消息框,其中包含如下文本:"a copy was sended to your email"
ASP.NETvb背后的代码
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>
你什么也没得到的原因是你的按钮没有绑定到你的点击功能。您要么必须向按钮添加一个 onclick,要么必须向您的函数添加一个 handles 事件。
<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"