Hey all, this is kind of a 3 part question/request.
I have a contact form where I want online users to fill in their name, email and message and press submit to send that information to the site admin.
I want to do 3 things with this.
1) I want to check and make sure the user has entered the correct info (i believe I have already done that with field validators.
2) I want the email sent to the site admin (this part works, but it actually sends the email 2x. once with the full info the user entered and the second is a blank email).
3) I want the information from the Name and Email sent to a database (maybe xml or csv file) to pull for email blasts/tracking etc.
Right now, I'm able to check for name, email and message and send the email but not much more and I am not exactly sure how to get an .aspx file to show up as an .html file for web browser viewing.
Now I'm a LONG way from school and don't remember exactly how to do this stuff but i'm sure there's got to be a tutorial or link out there somewhere that goes through this step by step that you guys may know about.
I've also placed my code below for anyone willing to chime in on where I'm going wrong.
Thanks in advance.
Here is the code from my Default.aspx.vb file
Imports System.Net.Mail
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Public Sub ClearForm()
txtName.Text = String.Empty
txtEmail.Text = String.Empty
txtMsg.Text = String.Empty
End Sub
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
mail = New MailMessage()
mail.From = New MailAddress("Comments@email.com")
mail.To.Add("test@gmail.com")
mail.Subject = "Contact Message"
mail.Body = "Name: " & txtName.Text & Environment.NewLine & "Email Address: " & txtEmail.Text & Environment.NewLine & "Message: " & txtMsg.Text
mail.IsBodyHtml = False
SmtpServer.Send(mail)
MsgBox("Your Message Has Been Sent")
ClearForm()
End Sub
End Class
And then here is my code from the Default.aspx file
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
#form1 {
margin-right: 0px;
}
</style>
</head>
<body id="Body1" style="background-color: rgb(56,55,54); margin-right: 0px;" runat="server">
<form id="form1" runat="server">
<div style="height: 572px; width: 1180px;">
<img src="Contact.png" />
<div>
<asp:TextBox ID="txtName" runat="server" Style="position:absolute; width: 319px; height: 32px; top: 155px; left: 443px;" BorderStyle="None" TabIndex="1"></asp:TextBox>
<asp:RequiredFieldValidator ID="txtNameRequiredField" runat="server" ControlToValidate="txtName" Style="position:absolute; top: 175px; left: 612px; width: 153px;" ErrorMessage="Please Enter Your Name." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
</div>
<div>
<asp:TextBox ID="txtEmail" runat="server" Style="position:absolute; width: 319px; height: 32px; top: 252px; left: 443px;" BorderStyle="None" TabIndex="2"></asp:TextBox>
<asp:RequiredFieldValidator ID="txtEmailRequiredField" runat="server" ControlToValidate="txtEmail" Style="position:absolute; top: 272px; left: 582px; width: 208px;" ErrorMessage="Please Enter an Email Address." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" Style="position:absolute; top: 272px; left: 555px; width: 210px;" ErrorMessage="Please Enter A Valid Email Address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Font-Size="Small"></asp:RegularExpressionValidator>
</div>
<div>
<asp:TextBox ID="txtMsg" runat="server" Style="position:absolute; width: 323px; height: 175px; top: 349px; left: 441px;" BorderStyle="None" TabIndex="3" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="txtMsgRequiredField" runat="server" ControlToValidate="txtMsg" Style="position:absolute; top: 512px; left: 445px; height: 16px; width: 303px;" ErrorMessage="Please Enter A Message." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
</div>
<div>
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Style="position:absolute; top: 542px; left: 678px; width: 88px; height: 25px;" Text="Submit" BorderStyle="None" />
</div>
<div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="position:absolute; top: 368px; left: 454px; height: 147px; width: 285px;" BorderStyle="None" DisplayMode="List" Visible="False" />
</div>
</div>
</form>
</body>
</html>
Once again thanks in advance to anyone who can point me in the right direction. I am sure there's got to be a video tutorial of someone doing this. I just can't find it.