Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Form to Email is not working in my hosted page

$
0
0

I have created a Form to Email in my contact  page in order to allow users to communicate and interact with the site. However, When I hosted my website, I set the SMTP on live mail using 587 port. Then I decided to get a hosting mail from my service provider. So I configured my code behind according to the new server that is the hosting one. My problem is  the form doesn't like the new configuration and kept sending to my live mail. The e-mail is working perfectly in my development PC and doesn't give me any exception, but it doesn't work once uploaded into my domain file manager. 

I used Ajax toolkit to prevent postback in my page, add watermark and also using the update progress for loading purposes! I have a real doubt of using Ajax control toolkit by thinking it might be the main reason for the form not working as it supposes to be! Any help to solve this matter would be much appreciated

This is the form script:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>

<table >
<tr>
<td class="auto-style29" style="vertical-align:top; text-align: left;">
<asp:Label ID="Label1" runat="server" Font-Italic="False" Font-Names="Lucida Sans" Text="Name"></asp:Label>
</td>
<td style="text-align: left" class="auto-style30" >
<asp:TextBox ID="txtName" runat="server" CssClass="styling" width="350px"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtName_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtName" WatermarkCssClass="styling" WatermarkText="Enter your name">
</asp:TextBoxWatermarkExtender>
</td>
<td class="auto-style31">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" ErrorMessage="Your name is required!" ForeColor="Red" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style32" style="vertical-align:top; text-align: left;">
<asp:Label ID="Label4" runat="server" Font-Bold="False" Font-Italic="False" Font-Names="Lucida Sans" Text="Email" style="text-align: left"></asp:Label>
</td>
<td class="auto-style33">
<asp:TextBox ID="txtEmail" runat="server" CssClass="styling" width="350px"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtEmail_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtEmail" WatermarkCssClass="styling" WatermarkText="Enter your email">
</asp:TextBoxWatermarkExtender>
</td>
<td class="auto-style33">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtEmail" ErrorMessage="Your Email is required!" ForeColor="Red" Text="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Please enter a valid emaill " ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style32" style="vertical-align:top; text-align: left;">
<asp:Label ID="Label2" runat="server" Font-Bold="False" Font-Italic="False" Font-Names="Lucida Sans" Text="Subject" style="text-align: left"></asp:Label>
</td>
<td class="auto-style33">
<asp:TextBox ID="txtSubject" runat="server" CssClass="styling" width="350px"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtSubject_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtSubject" WatermarkCssClass="styling" WatermarkText="Enter a subject">
</asp:TextBoxWatermarkExtender>
</td>
<td class="auto-style33">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtSubject" ErrorMessage="Subject is required!" ForeColor="Red" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style34" style="vertical-align:top; text-align: left;">
<asp:Label ID="Label3" runat="server" Font-Italic="False" Font-Names="Lucida Sans" Text="Message" style="text-align: left"></asp:Label>
</td>
<td class="auto-style26" style="vertical-align:top;">
<asp:TextBox ID="txtMessage" runat="server" CssClass="styling" Height="80px" Rows="5" TextMode="MultiLine" width="389px"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtMessage_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtMessage" WatermarkCssClass="styling" WatermarkText="Enter your message">
</asp:TextBoxWatermarkExtender>
</td>
<td class="auto-style34" style="vertical-align:top;">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtMessage" ErrorMessage="Message is required!" ForeColor="Red" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style45" colspan="3">
<asp:Label ID="lblmsg" runat="server" Font-Bold="True" Font-Names="Lucida Sans"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style27" colspan="3">
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<asp:Image ID="Image3" runat="server" Height="27px" ImageUrl="~/Images/loading.gif" style="text-align: right" Width="42px" />
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
<tr>
<td class="auto-style8" colspan="3">

<asp:Button ID="btnSub" runat="server" BackColor="#916E80" BorderColor="#916E80" Font-Bold="True" Font-Names="Lucida Sans" ForeColor="White" Text="Submit" Height="35px" Width="84px" OnClick="btnSub_Click1" />

</td>
</tr>

<tr>
<td class="auto-style10" colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Font-Names="Lucida Sans" ForeColor="Red" HeaderText="Please correct the following errors!" Width="299px" />
</td>
</tr>
<tr>
<td class="auto-style19" colspan="3">
&nbsp;</td>
</tr>
</table>

</ContentTemplate>
</asp:UpdatePanel>

This is the code behind for event:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Net.Mail;
using System.Web.UI.WebControls;

namespace Christech
{
public partial class ContactUs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/scripts/jquery-1.9.1.js"
});

}

protected void btnSub_Click1(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000);
try
{

MailMessage mail = new MailMessage();
mail.From = new MailAddress(txtEmail.Text);
mail.To.Add("Myhostingmail@mail.com");
mail.Subject = txtSubject.Text;
mail.Body = "<b> Sender Name: </b>" + txtName.Text + "<br/>"
+ "<b> Sender Email: </b>" + txtEmail.Text + "<br/>"
+ "<b> Sender Comment: </b>" + txtMessage.Text;
mail.IsBodyHtml = true;

SmtpClient smtpClient = new SmtpClient("server@mail.com", 587);
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new
System.Net.NetworkCredential("Myhostingmail@mail.com", "Password");
smtpClient.Send(mail);

lblmsg.Text = "Thank you for contacting us";

txtName.Text = "";
txtEmail.Text = "";
txtSubject.Text = "";
txtMessage.Text = "";


}

catch (Exception ex)
{
lblmsg.Text = "An unexpected error has occured! " + ex.Message;


}
}
}
}


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>