Guest User

Untitled

a guest
Feb 20th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.82 KB | None | 0 0
  1. <h2>Contact Us</h2>
  2. <br />
  3. <table>
  4.     <!-- Name -->
  5.     <tr>
  6.         <td align="center">
  7.             Name:</td>
  8.         <td>
  9.             <asp:TextBox ID="txtName"
  10.                             runat="server"
  11.                             Columns="50"></asp:TextBox>
  12.         </td>
  13.     </tr>
  14.  
  15.     <!-- Subject -->
  16.     <tr>
  17.         <td align="center">
  18.             Subject:
  19.         </td>
  20.         <td>
  21.             <asp:DropDownList ID="ddlSubject" runat="server">
  22.                 <asp:ListItem>Ask a question</asp:ListItem>
  23.                 <asp:ListItem>Report a bug</asp:ListItem>
  24.                 <asp:ListItem>Customer support ticket</asp:ListItem>
  25.                 <asp:ListItem>Other</asp:ListItem>
  26.             </asp:DropDownList>
  27.         </td>
  28.     </tr>
  29.  
  30.     <!-- Message -->
  31.     <tr>
  32.         <td align="center">
  33.             Message:
  34.         </td>
  35.         <td>
  36.             <asp:TextBox ID="txtMessage"
  37.                             runat="server"
  38.                             Columns="40"
  39.                             Rows="6"
  40.                             TextMode="MultiLine"></asp:TextBox>
  41.         </td>
  42.     </tr>
  43.  
  44.     <!-- Submit -->
  45.     <tr align="center">
  46.         <td colspan="2">
  47.             <asp:Button ID="btnSubmit" runat="server" Text="Submit"
  48.                 onclick="btnSubmit_Click" />
  49.         </td>
  50.     </tr>
  51.            
  52.     <!-- Results -->
  53.     <tr align="center">
  54.         <td colspan="2">
  55.             <asp:Label ID="lblResult" runat="server"></asp:Label>
  56.         </td>
  57.     </tr>
  58. </table>
  59.  
  60.  
  61.  
  62. <!------ C# _-------->
  63. try
  64. {
  65.     //Create the msg object to be sent
  66.     MailMessage msg = new MailMessage();
  67.     //Add your email address to the recipients
  68.     msg.To.Add("RecipientAddress@gmail.com");
  69.     //Configure the address we are sending the mail from
  70.     MailAddress address = new MailAddress("SenderAddress@gmail.com");
  71.     msg.From = address;
  72.     //Append their name in the beginning of the subject
  73.     msg.Subject = txtName.Text + " :  " + ddlSubject.Text;
  74.     msg.Body = txtMessage.Text;
  75.  
  76.     //Configure an SmtpClient to send the mail.
  77.     SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
  78.     client.EnableSsl = true; //only enable this if your provider requires it
  79.     //Setup credentials to login to our sender email address ("UserName", "Password")
  80.     NetworkCredential credentials = new NetworkCredential("SenderAddress@gmail.com", "xxxx");
  81.     client.Credentials = credentials;
  82.  
  83.     //Send the msg
  84.     client.Send(msg);
  85.  
  86.     //Display some feedback to the user to let them know it was sent
  87.     lblResult.Text = "Your message was sent!";
  88.  
  89.     //Clear the form
  90.     txtName.Text = "";
  91.     txtMessage.Text = "";
  92. }
  93. catch
  94. {
  95.     //If the message failed at some point, let the user know
  96.     lblResult.Text = "Your message failed to send, please try again.";
  97. }
Add Comment
Please, Sign In to add comment