datzent83
asked on
VB.NET Email with Checkboxes
In the following code, how do I add
If checkbox1 is checked then add "checkbox 1 is checked"
If checkbox2 is checked then add "checkbox 2 is checked"
into the body of the email?
If checkbox1 is checked then add "checkbox 1 is checked"
If checkbox2 is checked then add "checkbox 2 is checked"
into the body of the email?
<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">
Sub Send2Mail (sender as Object, e as EventArgs)
Dim objMail as New MailMessage()
objMail.To = "test@test.com"
objMail.From = strEmail.Text
objMail.BodyFormat = MailFormat.Text
objMail.Priority = MailPriority.Normal
objMail.Subject = "Web Contact"
objMail.Body = "Name: " + strName.Text + vbNewLine + "Email: " + strEmail.text + vbnewLine + "Work Phone: " + strWrkPhone.Text + vbnewLine + "Home Phone: " + strHomePhone.Text + vbnewLine + "Fax Number: " + strFaxNumber.Text + vbnewLine + "Message: " + strYourMsg.text
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(objMail)
Response.Redirect("email_confirm.htm")
End Sub
</script>
You can append to the body property conditionally.
Sub Send2Mail(ByVal sender As Object, ByVal e As EventArgs)
Dim objMail As New MailMessage()
objMail.To = "igors@optimumcomp.com"
objMail.From = strEmail.Text
objMail.BodyFormat = MailFormat.Text
objMail.Priority = MailPriority.Normal
objMail.Subject = "HealthyChats.com Spanish Web Contact"
objMail.Body = "Name: " + strName.Text + vbNewLine + "Email: " + strEmail.text + vbnewLine + "Work Phone: " + strWrkPhone.Text + vbnewLine + "Home Phone: " + strHomePhone.Text + vbnewLine + "Fax Number: " + strFaxNumber.Text + vbnewLine + "Message: " + strYourMsg.text
If checkbox1.Checked Then
objMail.Body &= vbNewLine & "checkbox1 is checked"
End If
If checkbox2.Checked Then
objMail.Body &= vbNewLine & "checkbox2 is checked"
End If
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(objMail)
Response.Redirect("email_confirm.htm")
End Sub
ASKER
PaulHews: Is there a way to break each text onto a new line and move it above the name?
Thanks!
Thanks!
Can you please explain what you mean?
ASKER
When the email is recieved all the checkboxs texts is below the message (strYourMsg). I need it to be above the name (strName).
I need the email address and the phone numbers to be validated as well to make sure they type in the proper email addresses and phone numbers.
I need the email address and the phone numbers to be validated as well to make sure they type in the proper email addresses and phone numbers.
change line 16 to
objMail.Body =IIF(checkbox1.checked,"Checkbox1 is checked","") + vbNewLine + IIF(checkbox2.checked,"Checkbox2 is checked","")+ vbNewLine + "Name: " + strName.Text + vbNewLine + "Email: " + strEmail.text + vbnewLine + "Work Phone: " + strWrkPhone.Text + vbnewLine + "Home Phone: " + strHomePhone.Text + vbnewLine + "Fax Number: " + strFaxNumber.Text + vbnewLine + "Message: " + strYourMsg.text
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this is what I said in a single line in my comment #26595464
Open in new window