New to .Net - using the 4Guys example to send email form data via email.
I'm getting stuck though when trying to add more fields to form and therefore the actual email sent.
Any help would be grateful!!
Code below :
<script language="vb" runat="server"
Sub btnSendFeedback_Click(sender as Object, e as EventArgs)
'Create an instance of the MailMessage class
Dim objMM as New MailMessage()
'Set the properties - send the email to the person who filled out the
'feedback form.
objMM.To = "me@dotnet.itags.org.mydomain"
objMM.From = txtEmail.Text
'If you want to CC this email to someone else, uncomment the line below
'objMM.Cc = "someone@dotnet.itags.org.someaddress.com"
'If you want to BCC this email to someone else, uncomment the line below
'objMM.Bcc = "someone@dotnet.itags.org.someaddress.com"
'Send the email in text format
objMM.BodyFormat = MailFormat.Text
'(to send HTML format, change MailFormat.Text to MailFormat.Html)
'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal
'Set the subject
objMM.Subject = "Email Test"
'Set the body
objMM.Body = txtName.Text & vbCrLf _ txtPhone.Text & vbCrLf _ txtComments.Text & vbCrLf _ txtEmail.Text
'Specify to use the default Smtp Server
SmtpMail.SmtpServer = "mymailserver"
'Now, to send the message, use the Send method of the SmtpMail class
SmtpMail.Send(objMM)
panelSendEmail.Visible = false
panelMailSent.Visible = true
End Sub
</script
<asp:panel id="panelSendEmail" runat="server">
<form runat="server">
<p>We are interested in your feedback! Please enter the following
requested information below to send us your comments.</p>
<p>Your Name:
<asp:textbox id="txtName" runat="server" /></p>
<p>Your Email Address:
<asp:textbox id="txtEmail" runat="server" /></p>
<p>Your Phone Number:
<asp:textbox id="txtPhone" runat="server" /></p>
<p>Your Message:</p>
<p><asp:textbox id="txtComments" TextMode="MultiLine"
Columns="40" Rows="10" runat="server" /></p>
<p> <asp:button runat="server" id="btnSendFeedback" Text="Send Feedback!"
OnClick="btnSendFeedback_Click" /></p>
</form>
</asp:panel>
<asp:panel id="panelMailSent" runat="server" Visible="False">
<p>An email has been sent to the email address you specified. Thanks!</p>
</asp:panel>Hi,
nice code but what exactly is the error you experience? Did the code you copied from the site of 4guys work on your system before you altered the code?
Grz, Kris.
Kris,
Many thanks for your reply...
The problem i am having (and have tried many variations to correct) is with the objMMbody and declaring what to send to the mail recepient.
If i change the code to this :
<code
'Set the body
objMM.Body = txtName.text + txtPhone.text + txtComments.text + txtEmail.text
<code/
It works fine.
But i want to be able to add headers for the form data such as "Name: txtName.text" with a CR to make it neat to the end user.
Help!!
TIA
This might help:http://www.systemwebmail.com/faq/2.8.aspx.
Thanks for the URL but this is not what i am trying to achieve as per my last post...all i think i need to know is the syntax for separating by a <CR> the form data in the email that i want to send...i have tried vbCRLF and chr13 etc but not in the correct way i think...
TIA
Hi Jezzer,
try this one out:Environment.NewLine Property.
Grz, Kris.
0 comments:
Post a Comment