I have a rather large form that customers are filling out ( about 360 fields worth of data). I am using the a Wizard with Steps and on the Finish Button Click event I want to send all that form data as an email to a specified department within my company.
I can get the email to send no problem. However it sends all the field info as plain text, which is hard to read. I have since created an html template with the token ##fieldname## and I need to replace the token with the data from the form and then send the
template via email. I am using VB and not C# and I am rather new to VB. I am sure there is a way to do this but I am at my wits end trying to figure it out. If anyone can point me in the right direction please do so.
to send html email, you need to send IsBodyHtml property of MailMessage to true and then give the html string as body to MailMessage and send it...
so what you would do is read generic html template as dtring, then use Regex or String.Replace() to put your field values in to that string...then take that string ans give it as Body to MailMessage...
Chawx84
Member
3 Points
3 Posts
Send Form details to Email via HTML Template
Apr 18, 2012 02:42 PM|LINK
I have a rather large form that customers are filling out ( about 360 fields worth of data). I am using the a Wizard with Steps and on the Finish Button Click event I want to send all that form data as an email to a specified department within my company. I can get the email to send no problem. However it sends all the field info as plain text, which is hard to read. I have since created an html template with the token ##fieldname## and I need to replace the token with the data from the form and then send the template via email. I am using VB and not C# and I am rather new to VB. I am sure there is a way to do this but I am at my wits end trying to figure it out. If anyone can point me in the right direction please do so.
ramiramilu
All-Star
95275 Points
14072 Posts
Re: Send Form details to Email via HTML Template
Apr 18, 2012 04:03 PM|LINK
to send html email, you need to send IsBodyHtml property of MailMessage to true and then give the html string as body to MailMessage and send it...
so what you would do is read generic html template as dtring, then use Regex or String.Replace() to put your field values in to that string...then take that string ans give it as Body to MailMessage...
for more information - http://systemnetmail.com/
Thanks,
JumpStart
ahmed gad
Member
115 Points
94 Posts
Re: Send Form details to Email via HTML Template
Apr 18, 2012 04:27 PM|LINK
Protected Sub btnsend_Click(sender As Object, e As System.EventArgs) Handles btnsend.Click Dim Name, Mail, Phone, Enquiry, userName As String Name = txtName.Text Mail = txtmail.Text Phone = txtphone.Text Enquiry = txtenquiry.Text If User.Identity.Name = "" Then userName = "Not member" Else userName = User.Identity.Name End If Dim Email As New System.Net.Mail.MailMessage("System@xxxxxxxxxx.com", "ahmed@xxxxxxxxxxx.com") Email.Subject = "New Enquiry" Email.Body = "<html>" & vbCrLf & _ " <body>" & vbCrLf & _ " <h1>New Comments or Enquiry had been sent</h1>" & vbCrLf & _ " <table cellpadding=""5"" cellspacing=""0"" border=""1"">" & vbCrLf & _ " <tr>" & vbCrLf & _ " <tdtext-align: right;font-weight: bold"">Name:</td>" & vbCrLf & _ " <td>" + Name + "</td>" & vbCrLf & _ " </tr>" & vbCrLf & _ " <tr>" & vbCrLf & _ " <tdtext-align: right;font-weight: bold"">Email:</td>" & vbCrLf & _ " <td>" + Mail + "</td>" & vbCrLf & _ " </tr>" & vbCrLf & _ " <tr>" & vbCrLf & _ " <tdtext-align: right;font-weight: bold"">Phone:</td>" & vbCrLf & _ " <td>" + Phone + "</td>" & vbCrLf & _ " </tr>" & vbCrLf & _ " <tr>" & vbCrLf & _ " <tdtext-align: right;font-weight: bold"">Enquiry:</td>" & vbCrLf & _ " <td>" + Enquiry + "</td>" & vbCrLf & _ " </tr>" & vbCrLf & _ " <tr>" & vbCrLf & _ " <tdtext-align: right;font-weight: bold"">User:</td>" & vbCrLf & _ " <td>" + userName + "</td>" & vbCrLf & _ " </tr> " & vbCrLf & _ " </table>" & vbCrLf & _ " </body>" & vbCrLf & _ "</html>" 'Email.Bcc.Add("ahmed@xxxxxxxxxx.com") Email.IsBodyHtml = True Dim mailClient As New System.Net.Mail.SmtpClient() 'This object stores the authentication values Dim basicAuthenticationInfo As _ New System.Net.NetworkCredential("System@xxxxxxxxxxxxx.com", "xxxxxxxxxx") 'Put your own, or your ISPs, mail server name onthis next line mailClient.Host = "mail.papayshop.com" mailClient.UseDefaultCredentials = False mailClient.Credentials = basicAuthenticationInfo mailClient.Send(Email) End Subplease mark answer
Chawx84
Member
3 Points
3 Posts
Re: Send Form details to Email via HTML Template
Aug 10, 2012 12:35 PM|LINK
Ahmed....you are a genius.
tola_cis
Member
8 Points
4 Posts
Re: Send Form details to Email via HTML Template
Nov 12, 2012 08:15 AM|LINK
hello
if someone can help me in my website issue
i am not profionial in ASP.net with VB
i ma using this code for hit counter to count the number of visitor but this error appeare for me
00000
it could not be obtained due to the following error]: Conversion from string "" to type 'Integer' is not valid
and this is the code here
Imports System.IO
Partial Class Controls_counter
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objReader As StreamReader
Dim objWriter As StreamWriter
Dim sFile As String
Dim sCount As String
Dim iCount As Integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If Not File.Exists(sFile) Then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close()
End If
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close()
iCount = CInt(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close()
Catch Ex As Exception
Label1.Width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = "00000" & sCount
End Try
End Sub
End Class