我想通过每次查询来发送到我的网站,但代码不起作用 [英] i want to sent by every enquiry thats come to my website,but code not working

查看:69
本文介绍了我想通过每次查询来发送到我的网站,但代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在提交按钮上写下了解决代码:



i write foluwing code on submit button:

Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Submit.Click
    If Full_Name.Text = "" And Subject.Text = "" And Message.Text = "" And Email_Address.Text = "" And AntiSpam.Text = "" Then
        MsgBox("Please fill Required field")
    Else<code></code>
        If AntiSpam.Text <> "25" Then
            MsgBox("Wrong answer")
        Else
            Dim messagebody As New Net.Mail.MailMessage(Email_Address.Text, "way2ankita@gmail.com", Subject.Text, Message.Text)
            Dim SMTPserver As New SmtpClient("smtp.gmail.com")
            SMTPserver.Port = 587
            SMTPserver.Credentials = New System.Net.NetworkCredential(Email_Address.Text, "123456")
            SMTPserver.EnableSsl = True
            SMTPserver.Host = "smtp.gmail.com"
            SMTPserver.Send(messagebody)

        End If
    End If
End Sub

推荐答案

您好,



您使用SMTPServer.Credentails是错误的。在这种方法中,您需要将您的凭证传递给Gmail,而不是用户的电子邮件地址。



所以这一行会变成类似:



Hello,

Your use of SMTPServer.Credentails is wrong. In this method you need to pass YOUR credential to Gmail, not the user email address.

So this line would become something like:

SMTPserver.Credentials = New System.Net.NetworkCredential("MyGmailAddress@gmail.com", "mySecretPassword")





只需用您的应用程序使用的帐户替换MyGmailAddress@gmail.com和mySecretPassword。



Valery。



just replace MyGmailAddress@gmail.com and mySecretPassword by the accounts that your application uses.

Valery.


解决方案1似乎是聪明的。

我不直接关注你所描述的问题,而是逻辑问题。

如果我是你,我会替换它:

Solution 1 seems to be the smart one.
Mine does not directly concerns the issue you are describing, but rather a problem of logic.
If I were you, I would replace this:
If Full_Name.Text = "" And Subject.Text = "" And Message.Text = "" And Email_Address.Text = "" And AntiSpam.Text = "" Then



,其中:


with that:

If Full_Name.Text = "" OrElse Subject.Text = "" OrElse Message.Text = "" OrElse Email_Address.Text = "" OrElse AntiSpam.Text = "" Then



为什么?因为,如果不这样做,只有在根本没有给出任何信息时才会出现说明必填字段的消息框。如果缺少任何必填字段,则会出现此消息框的正确行为。


Why? Because, if you don't, the message box stating required fields have to be filled will only appear if no information is given at all. Correct behaviour would be this message box appears if any of the required fields is missing.


这篇关于我想通过每次查询来发送到我的网站,但代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆