Bellow is the code for a button where i am trying to execute an email valiadator before and email is sent. The if statement works great until i enter the msgmail code in it. then i get an invalid expression error.
Can someone please help me with this??
thanks
protected void Button1_Click(object sender, EventArgs e)
{
string patternLenient = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex reLenient = new Regex(patternLenient);
bool isLenientMatch = reLenient.IsMatch(txtEmail.Text);
MailMessage msgMail = new MailMessage();
if (isLenientMatch)
msgMail.To = "aaaaa@gmail.com";
msgMail.From = txtEmail.Text;
msgMail.Subject = txtSubject.Text;
msgMail.BodyFormat = MailFormat.Html;
msgMail.Body = txtBody.Text + " <html><body><br /><br /></body></html>" + txtName.Text;
SmtpMail.SmtpServer = "smtp1r.cp.blacknight.com";
SmtpMail.Send(msgMail);
this.ClientScript.RegisterStartupScript(this.GetType(), "Thank You", "<script language=\"javaScript\">" + "alert('Thank for your query, we will contact you within the next 24hours.');" + "window.location.href='Contact.aspx';" + "<" + "/script>");
else
this.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script language=\"javaScript\">" + "alert('Please enter a valid email address to proceed.');" + "<" + "/script>");
txtEmail.Focus();