Hello
This is my first website I have built and followed all the steps from the book. I think the book is great.
My problem is when I click the send button and I get the below error:-
Server Error in '/' Application.
The specified string is not in the form required for an e-mail address.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.
Source Error:
Line 25: mailbody = mailbody.Replace("##Query##", txtQuery.Text);
Line 26:
Line 27: MailMessage myMessage = new MailMessage();
Line 28: myMessage.Subject = "Message from fuller Inspirations website";
Line 29: myMessage.Body = mailbody;
My code is:-
<code>
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
<system.net>
<mailSettings>
<smtp from="mail.mydomain.com">
<network host="smtp.mail.mydomain.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class Contact_WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
{
if (Page.IsValid)
{
string filename = Server.MapPath("~/App_Data/ContactForm.txt");
string mailbody = System.IO.File.ReadAllText(filename);
mailbody = mailbody.Replace("##Name##", txtName.Text);
mailbody = mailbody.Replace("##Number##", txtNumber.Text);
mailbody = mailbody.Replace("##Email##", txtEmail.Text);
mailbody = mailbody.Replace("##Query##", txtQuery.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Message from fuller Inspirations website";
myMessage.Body = mailbody;
myMessage.From = new MailAddress("
[email protected]", "my website");
myMessage.To.Add(new MailAddress("
[email protected]", "my website"));
SmtpClient mySmtpClient = new SmtpClient("mail.domainname.com");
mySmtpClient.Send(myMessage);
lblMessage.Visible = true;
FormTable.Visible = false;
}
}
}
}
</code>
I look forward to your help.
Thanks