0
好吧,基本上我的網站上有一個評論表。人們只是在評論框中發表評論,並將評論通過電子郵件發送給我的電子郵件。電子郵件部分工作正常,並通過。但是,當我嘗試清除表單域時出現錯誤。它給我一個錯誤說:參數'from'不能是空字符串。參數名稱:從
錯誤:參數'從'不能是一個空字符串。 參數名稱:從
所以任何人有任何想法?就像我說的電子郵件部分工作正常,它只是清除場是給我找麻煩
這裏是代碼:
Imports System.Web.Mail
Imports System.Text
Partial Class Pages_ContactUs : Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim body As String = "From: " + YourName.Text + " " + Environment.NewLine + "Email: " + YourEmail.Text + Environment.NewLine + Environment.NewLine + "Message: " + Environment.NewLine + Comments.Text
Dim MM As New System.Net.Mail.SmtpClient
MM.EnableSsl = True
MM.Host = "smtp.gmail.com"
Dim cred As New System.Net.NetworkCredential("[email protected]", "myPassword")
MM.Credentials = cred
MM.Send(YourEmail.Text, "[email protected]", Subject.Text, body)
ClearFields()
lblEmail.ForeColor = Drawing.Color.Green
lblEmail.Text = "Your message has been sent successfuly"
lblEmail.Visible = True
End Sub
Protected Sub ClearFields()
YourName.Text = ""
YourEmail.Text = ""
Comments.Text = ""
Subject.Text = ""
End Sub
End Class
沒有爲我工作。它表示'MailMessage'不明確,從命名空間或類型'System.Net.Mail',System.Web.Mail' – user2821331
導入使用完全限定名稱空間。 – OneFineDay
現在確定它說我的用戶名和密碼沒有聲明。它可能無法訪問,由於其保護級別 – user2821331