I am trying to send an email from my web site, MervNorton.com I am using the code provided by DiscountASP, How to send email in ASP.NET 2.0 - SMTP authentication. The code works. I then created a simple input form that only includes the addressees email address and a Message. The following is the line of code I changed and the line of code after changing. mail.To.Add( "[email protected]" ); Original mail.To.Add( txtEmail ); Revised txtEmail is the ID of a Email TextBox on the Input Form. Go to www.MervNorton.com and click on my photo to access the Input Form and enter your own Email Address and you can see the problem. If I can solve this problem I can create a new Input Form with additional variables. What is my problem and what is the solution.
I tried that and get the following message: Compiler Error Message: CS0103: The name 'txtMail' does not exist in the current context Source Error: Line 13: mail.Subject = "This is a test message" ; Line 14: mail.Body = "If you can see this mail, your SMTP service is working" ; Line 15: mail.To.Add( txtMail.Text ); Line 16: SmtpClient smtp = new SmtpClient( "smtp.MervNorton.com" ); Line 17:
Spelling error. It's txtEmail.Text, not txtMail.txt as in your code. So either change your code or the ID of your control.
I'm checking right now, and your post is correct: Line 15: mail.To.Add(txtMail.Text); It should be mail.To.Add(txtEMail.Text); Recompile your application and re-upload if necessary.
I'm not sure if the problem was because you had extra white spaces in parts of your code, spelled the ID "txtEmail" incorrectly (it was a small m, not capital M), or if it was because you put the code in the Page_Load event handler, causing the control not to be rendered first prior to execution of sending email, but I have debugged all of that and placed a working script in your account that you can review. The file name is TestEmail2.aspx.