Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h2>Contact Us</h2>
- <br />
- <table>
- <!-- Name -->
- <tr>
- <td align="center">
- Name:</td>
- <td>
- <asp:TextBox ID="txtName"
- runat="server"
- Columns="50"></asp:TextBox>
- </td>
- </tr>
- <!-- Subject -->
- <tr>
- <td align="center">
- Subject:
- </td>
- <td>
- <asp:DropDownList ID="ddlSubject" runat="server">
- <asp:ListItem>Ask a question</asp:ListItem>
- <asp:ListItem>Report a bug</asp:ListItem>
- <asp:ListItem>Customer support ticket</asp:ListItem>
- <asp:ListItem>Other</asp:ListItem>
- </asp:DropDownList>
- </td>
- </tr>
- <!-- Message -->
- <tr>
- <td align="center">
- Message:
- </td>
- <td>
- <asp:TextBox ID="txtMessage"
- runat="server"
- Columns="40"
- Rows="6"
- TextMode="MultiLine"></asp:TextBox>
- </td>
- </tr>
- <!-- Submit -->
- <tr align="center">
- <td colspan="2">
- <asp:Button ID="btnSubmit" runat="server" Text="Submit"
- onclick="btnSubmit_Click" />
- </td>
- </tr>
- <!-- Results -->
- <tr align="center">
- <td colspan="2">
- <asp:Label ID="lblResult" runat="server"></asp:Label>
- </td>
- </tr>
- </table>
- <!------ C# _-------->
- try
- {
- //Create the msg object to be sent
- MailMessage msg = new MailMessage();
- //Add your email address to the recipients
- msg.To.Add("RecipientAddress@gmail.com");
- //Configure the address we are sending the mail from
- MailAddress address = new MailAddress("SenderAddress@gmail.com");
- msg.From = address;
- //Append their name in the beginning of the subject
- msg.Subject = txtName.Text + " : " + ddlSubject.Text;
- msg.Body = txtMessage.Text;
- //Configure an SmtpClient to send the mail.
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
- client.EnableSsl = true; //only enable this if your provider requires it
- //Setup credentials to login to our sender email address ("UserName", "Password")
- NetworkCredential credentials = new NetworkCredential("SenderAddress@gmail.com", "xxxx");
- client.Credentials = credentials;
- //Send the msg
- client.Send(msg);
- //Display some feedback to the user to let them know it was sent
- lblResult.Text = "Your message was sent!";
- //Clear the form
- txtName.Text = "";
- txtMessage.Text = "";
- }
- catch
- {
- //If the message failed at some point, let the user know
- lblResult.Text = "Your message failed to send, please try again.";
- }
Add Comment
Please, Sign In to add comment