从网站的联系页面发送电子邮件 [英] sending email from contact page of website
问题描述
我一直在尝试找出如何从我的网站的联系页面上的用户输入发送电子邮件消息,并正在使用Visual Studio2010.理想情况下,用户应输入其姓名,电子邮件地址,电话数字,以及在文本框中的简短说明 联系人页面,当他们单击提交"按钮时,它会向我发送一封电子邮件.我的代码是:
i have been trying to figure out how to send an email message from user input on a contact page of my website, and am using visual studio 2010. ideally, the user would input their name, email address, phone number, and a short description in text boxes on a contact page, and when they click the submit button, it generates an email message to me. the code i have is:
受保护的子SendEmail_Click(ByVal发件人为对象,ByVal e为System.EventArgs)处理SendEmail.Click
常量ToAddress为字符串="contact@kitswv.com"
变暗为新MailMessage(UsersEmail.Text,ToAddress)
mm.Subject = Subject.Text
mm.Body = Body.Text
mm.IsBodyHtml = False
昏暗的smtp作为新的SmtpClient
smtp.Send(mm)
EmailSentForm.Visible = True
EmailForm.Visible = False
结束子
受保护的子Page_Load(将ByVal发送者作为对象,将ByVal e作为System.EventArgs)处理Me.Load
如果不是Page.IsPostBack然后
EmailSentForm.Visible = False
如果结束
结束子
结束班
Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click
Const ToAddress As String = "contact@kitswv.com"
Dim mm As New MailMessage(UsersEmail.Text, ToAddress)
mm.Subject = Subject.Text
mm.Body = Body.Text
mm.IsBodyHtml = False
Dim smtp As New SmtpClient
smtp.Send(mm)
EmailSentForm.Visible = True
EmailForm.Visible = False
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
EmailSentForm.Visible = False
End If
End Sub
End Class
我尝试过不同人的代码,它来自4guysfromrolla,看上去比我的代码简单一些,但是当我尝试构建页面时却出现了相同的错误,它说在这种情况下某些部分无法访问因为它是朋友. 该代码具有最多的错误,例如emailsentform.visible和mmbody之类的地方.代码看起来很干净,为什么会出现这些错误?这应该很容易,但现在已经有两天了.请帮助
i have tried code from different people, and this came from 4guysfromrolla, looked a little simpler than what i had, but it gives the same errors when i try to build the page, it says some sections are not accessible in this context because it is a friend. this code has the most errors, places like emailsentform.visible, and mmbody. the code looks clean, why am i getting these errors? this should be easy but it's been two days now trying to get this. please help
推荐答案
尝试如下操作:
Try something like this:
Dim msg = New MailMessage()
Dim srv = New SmtpClient()
srv.Host = "SMTP SERVER COMPUTER NAME"
srv.Port = 0 'port number for smtp server
msg.From = New MailAddress("FROM ADDRESS")
msg.To.Add("TO ADDRESS")
msg.Subject = "SUBJECT"
msg.IsBodyHtml =
msg.Body = "BODY OF THE TEXT"
srv.Send(msg)
不要忘了包括Imports System.Net.Mail
Don't forget to include Imports System.Net.Mail
这篇关于从网站的联系页面发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!