简体   繁体   English

vb asp.net联系表格

[英]vb asp.net contact form

Have created a simple contact form for use on client's website and can get the email (i'm using my gmail account temporarily) but when it is sent it shows it is from me no matter what I put in the email field. 已经创建了一个简单的联系表单以在客户的网站上使用,并且可以获取电子邮件(我暂时使用我的gmail帐户),但是发送后无论我在电子邮件字段中输入什么内容,它都显示来自我。 Please help! 请帮忙! Probably something completely ignorant but please help! 可能是完全无知的东西,但请帮忙! I want the email to be derived from the txtEmail.text field. 我希望电子邮件来自txtEmail.text字段。 Is there something I need to add to my web.config or on GoDaddy side of things? 我需要添加到web.config或GoDaddy一侧吗? Thanks. 谢谢。 Below is my code. 下面是我的代码。 I am aware I need to include try catch and clear the fields, but that will come after I get this to work!! 我知道我需要包括尝试捕获并清除字段,但这将在我使它起作用之后进行!! And yes I did include my real credentials. 是的,我确实提供了我的真实凭证。

Imports System.Net.Mail.MailAddress
Imports System.Net.Mail.MailMessage
Imports System.Net.NetworkCredential
Imports System.Net.Mail



Partial Class Default2

Inherits System.Web.UI.Page

Protected Sub btnSubmit_Click1(ByVal sender As Object, ByVal e As System.EventArgs)   Handles          btnSubmit.Click



    Dim Msg As New MailMessage()

    ' Sender e-mail address.

    Msg.From = New MailAddress(txtEmail.Text)


    ' Recipient e-mail address.

    Msg.To.Add("lchevy5@gmail.com")


    Msg.Subject = txtSubject.Text

    Msg.Body = "Sent From:" & txtName.Text + Environment.NewLine + "Email:" & txtEmail.Text +    Environment.NewLine + txtMessage.Text

    ' your remote SMTP server IP.

    Dim smtp As New SmtpClient()

    smtp.Host = "smtp.gmail.com"

    smtp.Port = 25

    smtp.Credentials = New System.Net.NetworkCredential("user", "pass")

    smtp.EnableSsl = True

    smtp.Send(Msg)

    'Msg = null;
    lbltexts.Visible = True




End Sub



End Class

Your code looks correct, but you're sending it through Gmail. 您的代码看起来正确,但是您正在通过Gmail发送。 Their SMTP server is likely rewriting the FROM field so that it matches the email address you're using for authentication. 他们的SMTP服务器可能会重写FROM字段,以使其与您用于身份验证的电子邮件地址匹配。

You might want to see this question . 您可能希望看到这个问题

Alternatively, you can send your mail through an SMTP server that doesn't do this. 或者,您可以通过不执行此操作的SMTP服务器发送邮件。

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 
Button2.Click
    Dim MyMessage As New MailMessage

    Try
        MyMessage.From = New MailAddress(TextBox2.Text)
        MyMessage.To.Add("Example@gmail.com")
        MyMessage.Subject = TextBox3.Text + body
        MyMessage.Body = TextBox4.Text
        Dim SMTP As New SmtpClient("smtp.gmail.com")
        SMTP.Port = 587
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential("Example@gmail.com", "Password")
        SMTP.Send(MyMessage)
        MessageBox.Show("Success")
    Catch ex As Exception
        MessageBox.Show("failed To Send")
    End Try
End Sub

Try this Code for Send Email For Your Specified Mail Id 尝试使用此代码发送指定电子邮件ID的电子邮件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM