Click here to Skip to main content
15,900,667 members
Home / Discussions / C#
   

C#

 
GeneralRe: Select a HostName with Regex in C# ? Pin
Mohammad Dayyan18-Feb-10 21:54
Mohammad Dayyan18-Feb-10 21:54 
GeneralRe: Select a HostName with Regex in C# ? Pin
AspDotNetDev18-Feb-10 22:00
protectorAspDotNetDev18-Feb-10 22:00 
QuestionC# forms Changing and Keeping default Values Pin
Nexusfactor18-Feb-10 16:21
Nexusfactor18-Feb-10 16:21 
GeneralRe: C# forms Changing and Keeping default Values Pin
AspDotNetDev18-Feb-10 17:00
protectorAspDotNetDev18-Feb-10 17:00 
AnswerRe: C# forms Changing and Keeping default Values Pin
Saksida Bojan18-Feb-10 20:42
Saksida Bojan18-Feb-10 20:42 
QuestionMessage Removed Pin
18-Feb-10 14:49
Nexusfactor18-Feb-10 14:49 
AnswerREPOST Pin
AspDotNetDev18-Feb-10 15:39
protectorAspDotNetDev18-Feb-10 15:39 
QuestionContact Me Form will send email through Localhost, but won't after I FTP it (C#) [modified] Pin
MasterMalli18-Feb-10 10:52
MasterMalli18-Feb-10 10:52 
I have made a contact me form for my website. When I was testing it with f5 in ASP.Net, the contact me page just reloaded itself after I submitted the information (like the Name, Phone Number, Email etc). But I still received the email containing the information I inputted into the Text Boxes in the Form.

So I decided to include a Try-Catch and redirect to a failure or success page depending on if it sent successfully... it always redirected to failure.html but I still received the email which is weird.

So I decided to FTP the site, it still redirects to failure.html but I don't receive any email anymore. There is clearly a problem here. I get no errors and no exception etc, so I have no indication onto where I'm going wrong. I will include all my coding.


contactme.aspx (just the form):


<div runat="server" id="form01">
    <table width="325" border="0">
      <tr>
        <td height="30" class="left"><asp:label runat="server" for="name">Name:</asp:label></td>
        <td>
          <asp:TextBox runat="server" class="input" type="text" name="name" id="name"></asp:TextBox></td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                ControlToValidate="name" ErrorMessage="Please input your name.">*</asp:RequiredFieldValidator>
          </td>
      </tr>
      <tr>
        <td height="30" class="left"><asp:label runat="server" for="number">Number:</asp:label></td>
        <td><asp:TextBox runat="server" class="input" type="text" name="number" id="number"></asp:TextBox></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="30" class="left"><asp:label runat="server" for="email">Email:</asp:label></td>
        <td><asp:TextBox runat="server" class="input" type="text" name="email" id="email"></asp:TextBox></td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                ControlToValidate="email" ErrorMessage="Please input an email address.">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                ControlToValidate="email" ErrorMessage="Please enter a valid email address."
                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
          </td>
      </tr>
      <tr>
        <td class="left"><asp:label runat="server" for="message">Message:</asp:label></td>
        <td>
          <asp:TextBox runat="server" class="input" name="essage" id="message" cols="45"
                rows="3" TextMode="MultiLine"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                ControlToValidate="message" ErrorMessage="Please input a message.">*</asp:RequiredFieldValidator>
          </td>
      </tr>
      <tr>
        <td class="left">&nbsp;</td>
        <td class="right"><label>
          <asp:button runat="server" class="submitBtn" name="submit"
                Text="Submit" id="cmdSubmit" onclick="submit_Click" />&nbsp;<asp:ValidationSummary
                ID="ValidationSummary" runat="server" CssClass="rightSpec"
                DisplayMode="List" />
            </label>
          </td>
      </tr>
    </table>
</div>



contactme.aspx.cs:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;


public partial class contactme : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void submit_Click(object sender, EventArgs e)
    {
        //try
        //{
            MailMessage messageC = new MailMessage();
            MailAddress to = new MailAddress("webdesign@malachijones.co.uk");
            messageC.To.Add(to);
            messageC.From = new MailAddress("webdesign@malachijones.co.uk", "site request");
            messageC.Subject = "malachijones.co.uk website request";
            messageC.IsBodyHtml = true;
            messageC.Body = "<html><head></head><body>" +
                        "<p></p>" +
                        "<p><strong>Name:</strong> " + name.Text + "</p>" +
                        "<p><strong>Phone Number:</strong> " + number.Text + "</p>" +
                        "<p><strong>Email Address:</strong> " + email.Text + "</p>" +
                        "<p><strong>Message:</strong> " + message.Text + "</p>" +
                        "</body></html>";

            SmtpClient smtpClient = new SmtpClient("smtpout.europe.secureserver.net");
            smtpClient.Credentials = new System.Net.NetworkCredential("webdesign@malachijones.co.uk", "My Password");
            smtpClient.Send(messageC);

            //Response.Redirect("success.html");
        //}
        //catch
        //{
            //Response.Redirect("failure.html");
        //}
    }
}



web.config:


<system.net>
        <mailSettings>
            <smtp from="webdesign@malachijones.co.uk">
                <network host="smtpout.europe.secureserver.net" port="25" userName="webdesign@malachijones.co.uk" password="My Password"/>
            </smtp>
        </mailSettings>
    </system.net>



Thanks in advance for any help.

Respect,

(*$malli$*)
modified on Thursday, February 18, 2010 7:35 PM

AnswerRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
Not Active18-Feb-10 13:20
mentorNot Active18-Feb-10 13:20 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
MasterMalli18-Feb-10 13:40
MasterMalli18-Feb-10 13:40 
AnswerRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
DaveyM6918-Feb-10 14:40
professionalDaveyM6918-Feb-10 14:40 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) [modified] Pin
MasterMalli18-Feb-10 15:33
MasterMalli18-Feb-10 15:33 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
MasterMalli18-Feb-10 15:46
MasterMalli18-Feb-10 15:46 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
DaveyM6918-Feb-10 16:34
professionalDaveyM6918-Feb-10 16:34 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
MasterMalli18-Feb-10 16:46
MasterMalli18-Feb-10 16:46 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
DaveyM6918-Feb-10 17:30
professionalDaveyM6918-Feb-10 17:30 
GeneralRe: Contact Me Form will send email through Localhost, but won't after I FTP it (C#) Pin
MasterMalli18-Feb-10 17:45
MasterMalli18-Feb-10 17:45 
QuestionMdichild form goes behind panel Pin
ronakT18-Feb-10 7:18
ronakT18-Feb-10 7:18 
AnswerRe: Mdichild form goes behind panel Pin
Abhinav S18-Feb-10 8:12
Abhinav S18-Feb-10 8:12 
GeneralRe: Mdichild form goes behind panel Pin
ronakT18-Feb-10 8:29
ronakT18-Feb-10 8:29 
GeneralRe: Mdichild form goes behind panel Pin
Abhinav S18-Feb-10 8:47
Abhinav S18-Feb-10 8:47 
GeneralRe: Mdichild form goes behind panel Pin
ronakT19-Feb-10 5:19
ronakT19-Feb-10 5:19 
GeneralRe: Mdichild form goes behind panel Pin
EliottA18-Feb-10 9:05
EliottA18-Feb-10 9:05 
GeneralRe: Mdichild form goes behind panel Pin
ronakT19-Feb-10 5:21
ronakT19-Feb-10 5:21 
QuestionValidation on Data Object in Code, not XAML? Pin
MattFunke18-Feb-10 4:25
MattFunke18-Feb-10 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.