Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2011, 03:23 PM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Contact form to email error

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
 
Old February 2nd, 2011, 05:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at this:

Code:
 
<smtp from="mail.mydomain.com">
The from attribute needs to contain an e-mail address (with an @) and not the name of the mail server.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 3rd, 2011, 02:50 PM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Hello

Works now.

Thanks for your help.
Bazmo





Similar Threads
Thread Thread Starter Forum Replies Last Post
email to send user data from contact form CheckBoxList tompatamcat ASP.NET 3.5 Basics 6 March 26th, 2013 12:11 AM
How to deliver the contact form information on yahoo email ? Abhishek Kumar ASP.NET 3.5 Basics 1 June 15th, 2010 10:52 AM
I need help with contact form iorgusu Need help with your homework? 1 September 27th, 2009 01:56 AM
Error With Contact Form ASP.NET 3.5 CSharpCoder BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 July 28th, 2008 04:08 PM
email contact forms xeno Beginning PHP 0 July 30th, 2005 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.