This will add an e-mail form to the Contact page. Probably not the best way to do it, but it works.
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Clubsite Contact Information"%>
<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>
<%@ Import Namespace="System.Net.Mail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script runat="server">
Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Dim SmtpClient As New SmtpClient
Dim message As New MailMessage
Try
Dim fromAddress As New MailAddress(txtEmail.Text, txtName.Text)
SmtpClient.Host = "YOUR SMTP SERVER"
SmtpClient.UseDefaultCredentials = True
SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpClient.Port = 25
lblStatus.Text = "Email successfully sent."
Catch ex As Exception
lblStatus.Text = "Send Email Failed.<br>" & ex.Message
End Try
End Sub
Sub btnReset_Click(ByVal Src As Object, ByVal e As EventArgs)
txtName.Text = ""
txtMessage.Text = ""
txtEmail.Text = ""
End Sub
</script>
This looks like precisely the workaround that I need since I cannot get Go Daddy to work with my SQL Server functionality (Web site developed with MS Viz Web Dev 2005 Express Ed). I was very excited to find it here!
I am getting a lot of errors on this code, though, that I can't figure them out. Can you help, please?
When I tried to run your script as is, I got an error on line 8 (Dim message As New MailMessage), saying: Make sure your arguments are in the right format:
------------------------------------------
The specified string is not in the form required for an e-mail address.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.
Source Error:
Line 5: Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Line 6: Dim SmtpClient As New SmtpClient
Line 7: Dim message As New MailMessage
Line 8: Try
Line 9: Dim fromAddress As New MailAddress(txtEmail.Text, txtName.Text)
Source File: C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\WebSites\Copy of HollywoodCalls\Member
-------------------------------------------------
I tried to get past this error by revising the line to "Dim message As New MailMessage(txtMessage.Text)", per the ASP.NET Tutorials on sending e-mails. But that addition prompts an error saying:
Error 9 Overload resolution failed because no accessible 'New' accepts this number of arguments.
Any ideas? I would so love to be able to use this clever workaround for my database fiasco. Thanks, dma
Thanks so much for returning to your earlier post.
I've entered the formatted e-mail lower in the script where it says to, but not on the MailMessage line where the error is occurring. Maybe the error is not pointing to that line?
I also wanted to modify the script so I could use "FormView" in ASP or even Wizards in ASP, so that people see an initial screen that they have to click past to get through to the from. I have tried every variation on this, including a separate wizards
tutorial at Microsoft that came with scripting. I still have endless bugs. I should add that I am hosted by Go Daddy, which has a gdform.asp that links with an html for routing. I don't even know if I can post an html form alongside all of my .aspx files.
Yes, I am green. But I am so close to having an incredibly awesome site that this form issue (and log in horror with Go Daddy's SQL Server) is blocking.
YOUR USER-FRIENDLY SCRIPT:
Go Daddy's host is secureserver.net. Does that need to go somewhere in the script (I've added it)? And I'm unclear why my e-mail address needs to be entered (although it is), since I am not sending the e-mails; my visitors are? Here is what I have so far,
which returns errors saying they are not declared (e.g., name txtMessage is not declared, etc.) so I can't even build it and test the mailing ability:
====================
<%@ Page Language="VB" MasterPageFile="~/insidepage.master" Title="Page Title" %>
<%@ Import Namespace="System.Net.Mail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script runat="server">
Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Dim SmtpClient As New SmtpClient
Dim message As New MailMessage
Try
Dim fromAddress As New MailAddress(txtEmail.Text)
SmtpClient.Host = "secureserver.net"
SmtpClient.UseDefaultCredentials = True
SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpClient.Port = 25
lblStatus.Text = "Application successfully submitted."
Catch ex As Exception
lblStatus.Text = "Submission Failed.<br>" & ex.Message
End Try
End Sub
Sub btnReset_Click(ByVal Src As Object, ByVal e As EventArgs)
txtFirstName.Text = ""
txtMessage.Text = ""
txtEmail.Text = ""
End Sub
</script>
*Below this is the ASP formview version of my form, with two views (ItemTemplate and InsertItemTemplate).
THE ALTERNATE MICROSOFT SCRIPT:
When I was defeated by the declaration errors on your simple page, I downloaded an MS Tutorial on Wizards and speedily built the same form using the Wizards Control. Sadly, I still don't know what to write in the script on the code-behind page to make the
form send. It doesn't work for me to use secureserver.net or smtp.secureserver.net as the mailServerName::
===================
Imports System.Net.Mail
Partial Class _scottsform
Inherits System.Web.UI.Page
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
SendMail(txtEmail.Text, txtFirstName.Text)
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)
Dim mailServerName As String = "secureserver.net"
(**I've also tried smtp.secureserver.net and relay-server.secureserver.net, those "mailbox names aren't allowed")
Dim message As MailMessage = New MailMessage(from, "me@mysite.com", "Application", body)
Dim mailClient As SmtpClient = New SmtpClient
mailClient.Host = mailServerName
mailClient.Send(message)
message.Dispose()
End Sub
End Class
Do you have any, any, any ideas on how to make either of these work? Thanks again. dma
I am having the same issue on godaddy I was wondering what exactly you had to do to correct this error? and did you end up using smtp.secureserver.net or relay-server.secureserver.net?
swpyatt
Member
58 Points
17 Posts
Contact Page - Send Form - VB
Jun 07, 2006 11:20 PM|LINK
This will add an e-mail form to the Contact page. Probably not the best way to do it, but it works.
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Clubsite Contact Information"%>
<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>
<%@ Import Namespace="System.Net.Mail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script runat="server">
Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Dim SmtpClient As New SmtpClient
Dim message As New MailMessage
Try
Dim fromAddress As New MailAddress(txtEmail.Text, txtName.Text)
SmtpClient.Host = "YOUR SMTP SERVER"
SmtpClient.UseDefaultCredentials = True
SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpClient.Port = 25
message.From = fromAddress
message.To.Add("EMAIL ADDRESS TO SEND TO")
message.Subject = "SUBJECT"
message.IsBodyHtml = False
message.Body = txtMessage.Text
SmtpClient.Send(message)
lblStatus.Text = "Email successfully sent."
Catch ex As Exception
lblStatus.Text = "Send Email Failed.<br>" & ex.Message
End Try
End Sub
Sub btnReset_Click(ByVal Src As Object, ByVal e As EventArgs)
txtName.Text = ""
txtMessage.Text = ""
txtEmail.Text = ""
End Sub
</script>
<div id="body">
<club:loginbanner id="LoginBanner1" runat="server" />
<div class="fullwidth">
<h2>
Contact Information</h2>
<p>
Text Here
</p>
</div>
<div class=fullwidth>
<table >
<tr>
<td><span style="font-family:Verdana; font-size:12px; font-weight:bold;color:Yellow;">Your Name:</span></td>
<td><asp:textbox id="txtName" Width="241" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td><span style="font-family:Verdana; font-size:12px; font-weight:bold;color:Yellow;">Your Email Address:</span></td>
<td><asp:textbox id="txtEmail" Width="241" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td colSpan="2" ><span style="font-family:Verdana; font-size:12px; font-weight:bold; color:Yellow;">Your Comment:</span></td>
</tr>
<tr>
<td align="center" colSpan="2" width=100%><asp:textbox id="txtMessage" Width="100%" Runat="server" Height="99" TextMode="MultiLine" MaxLength="400"></asp:textbox></td>
</tr>
<tr>
<td colSpan="2"> </td>
</tr>
<tr>
<td align=center><asp:button id="btnSendmail" Runat="server" Text="Send Mail" OnClick="btnSendmail_Click"></asp:button></td>
<td align=center><asp:button id="btnReset" Runat="server" Text="Reset" OnClick="btnReset_Click"></asp:button></td>
</tr>
<tr>
<td colSpan="2"><asp:label id="lblStatus" Runat="server" EnableViewState="False"></asp:label></td>
</tr>
</table>
</div>
</div>
</asp:Content>
swpyatt
Member
58 Points
17 Posts
Re: Contact Page - Send Form - VB
Jun 20, 2006 01:50 PM|LINK
lexy
Participant
1668 Points
441 Posts
Re: Contact Page - Send Form - VB
Jun 20, 2006 06:41 PM|LINK
Hi,
Yes nice.
Things seem to be a bit slow down here right now. Must be the summertime.
These things count in my book,
Keep it up,
Lex
dmitcha
Member
215 Points
43 Posts
Re: Contact Page - Send Form - VB
Sep 04, 2006 11:52 PM|LINK
This looks like precisely the workaround that I need since I cannot get Go Daddy to work with my SQL Server functionality (Web site developed with MS Viz Web Dev 2005 Express Ed). I was very excited to find it here!
I am getting a lot of errors on this code, though, that I can't figure them out. Can you help, please?
When I tried to run your script as is, I got an error on line 8 (Dim message As New MailMessage), saying: Make sure your arguments are in the right format:
------------------------------------------
The specified string is not in the form required for an e-mail address.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.
Source Error:
Line 5: Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Line 6: Dim SmtpClient As New SmtpClient
Line 7: Dim message As New MailMessage
Line 8: Try
Line 9: Dim fromAddress As New MailAddress(txtEmail.Text, txtName.Text)
Source File: C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\WebSites\Copy of HollywoodCalls\Member
-------------------------------------------------
I tried to get past this error by revising the line to "Dim message As New MailMessage(txtMessage.Text)", per the ASP.NET Tutorials on sending e-mails. But that addition prompts an error saying:
Error 9 Overload resolution failed because no accessible 'New' accepts this number of arguments.
Any ideas? I would so love to be able to use this clever workaround for my database fiasco. Thanks, dma
swpyatt
Member
58 Points
17 Posts
Re: Contact Page - Send Form - VB
Sep 05, 2006 04:17 PM|LINK
You are entering your e-mail address in the form in a correct e-mail format?
someone@somewhere.com? That may be the issue.
dmitcha
Member
215 Points
43 Posts
Re: Contact Page - Send Form - VB
Sep 05, 2006 08:10 PM|LINK
Thanks so much for returning to your earlier post.
I've entered the formatted e-mail lower in the script where it says to, but not on the MailMessage line where the error is occurring. Maybe the error is not pointing to that line?
I also wanted to modify the script so I could use "FormView" in ASP or even Wizards in ASP, so that people see an initial screen that they have to click past to get through to the from. I have tried every variation on this, including a separate wizards tutorial at Microsoft that came with scripting. I still have endless bugs. I should add that I am hosted by Go Daddy, which has a gdform.asp that links with an html for routing. I don't even know if I can post an html form alongside all of my .aspx files.
Yes, I am green. But I am so close to having an incredibly awesome site that this form issue (and log in horror with Go Daddy's SQL Server) is blocking.
YOUR USER-FRIENDLY SCRIPT:
Go Daddy's host is secureserver.net. Does that need to go somewhere in the script (I've added it)? And I'm unclear why my e-mail address needs to be entered (although it is), since I am not sending the e-mails; my visitors are? Here is what I have so far, which returns errors saying they are not declared (e.g., name txtMessage is not declared, etc.) so I can't even build it and test the mailing ability:
====================
<%@ Page Language="VB" MasterPageFile="~/insidepage.master" Title="Page Title" %>
<%@ Import Namespace="System.Net.Mail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script runat="server">
Sub btnSendmail_Click(ByVal Src As Object, ByVal e As EventArgs)
Dim SmtpClient As New SmtpClient
Dim message As New MailMessage
Try
Dim fromAddress As New MailAddress(txtEmail.Text)
SmtpClient.Host = "secureserver.net"
SmtpClient.UseDefaultCredentials = True
SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpClient.Port = 25
message.From = fromAddress
message.To.Add("me@mywebsite.com")
message.Subject = "APPLICATION"
message.IsBodyHtml = False
message.Body = txtMessage.Text
SmtpClient.Send(message)
lblStatus.Text = "Application successfully submitted."
Catch ex As Exception
lblStatus.Text = "Submission Failed.<br>" & ex.Message
End Try
End Sub
Sub btnReset_Click(ByVal Src As Object, ByVal e As EventArgs)
txtFirstName.Text = ""
txtMessage.Text = ""
txtEmail.Text = ""
End Sub
</script>
*Below this is the ASP formview version of my form, with two views (ItemTemplate and InsertItemTemplate).
THE ALTERNATE MICROSOFT SCRIPT:
When I was defeated by the declaration errors on your simple page, I downloaded an MS Tutorial on Wizards and speedily built the same form using the Wizards Control. Sadly, I still don't know what to write in the script on the code-behind page to make the form send. It doesn't work for me to use secureserver.net or smtp.secureserver.net as the mailServerName::
===================
Imports System.Net.Mail
Partial Class _scottsform
Inherits System.Web.UI.Page
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
SendMail(txtEmail.Text, txtFirstName.Text)
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)
Dim mailServerName As String = "secureserver.net"
Dim message As MailMessage = New MailMessage(from, "me@mysite.com", "Application", body)
Dim mailClient As SmtpClient = New SmtpClient
mailClient.Host = mailServerName
mailClient.Send(message)
message.Dispose()
End Sub
End Class
Do you have any, any, any ideas on how to make either of these work? Thanks again. dma
dmitcha
Member
215 Points
43 Posts
Re: Contact Page - Send Form - VB
Sep 05, 2006 11:07 PM|LINK
trainersonta...
Member
2 Points
1 Post
Re: Contact Page - Send Form - VB
Feb 27, 2008 05:21 PM|LINK
Hello,
I am having the same issue on godaddy I was wondering what exactly you had to do to correct this error? and did you end up using smtp.secureserver.net or relay-server.secureserver.net?
ChrisFROMtha...
Member
4 Points
6 Posts
Re: Contact Page - Send Form - VB
Mar 17, 2008 05:33 PM|LINK