Invalid character @ error in my mail script. What is wrong with the Script ( ASP.NET C#)

I keep getting the following error when I run this code. what is wrong with the code.  

An invalid character was found in the mail header: '@'.

string bmsg = "<h3>" + txtFirstName.Text + " " + txtLastName.Text + "</h3>";
            bmsg += "<p>This is your EPIC IPCST Conference Ticket Number &nbsp;<strong>" + lbInvoiceNumber.Text + "</strong>&nbsp; please keep this for your records";

            string pt = "mypw";
            [b]string cr = "";[/b]
            MailMessage mm = new MailMessage(cr, emc);

            mm.Subject = "2015 Conference Ticket";
            mm.Body = bmsg;

            mm.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "";
            smtp.EnableSsl = false;
            NetworkCredential NetworkCred = new NetworkCredential(cr, pt);
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 80;

Open in new window

An invalid character was found in the mail header: '@'.

Line 401 is where the error is coming form.
string cr = "";

Line 400:            string pt = "mypw";
Line 401:            string cr = "";
Line 402:            MailMessage mm = new MailMessage(cr, emc);

Open in new window

Thank you.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
string cr = "";
            MailMessage mm = new MailMessage(cr, emc);

what is EMC?
if you take out the cr and hardcode the string directly into it do you still get the error?

       MailMessage mm = new MailMessage("", emc);
bmanmike39Author Commented:
emc contains the senders email address, also ours.  (,

and yes, I still get the error.

This did work, But i don't know why or if it's safe or not.
string ourcopys = ",,";
MailMessage mm = new MailMessage(cr, emc + ourcopys);

Open in new window

Thank you!
Kyle AbrahamsSenior .Net DeveloperCommented:
can EMC be blank . . . that might be why you were throwing off the header.

I would also recommend bccing yourself rather then putting it in the "to".


There's nothing there that looks wrong outside of a possible blank or improperly formatted address.

You can also wrap it just to be sure:

MailMessage mm = new MailMessage(new MailAddress(cr), new MailAddress(emc));
Bcc.Add(new MailAddress(""));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.