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.  

Error:
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 = "my@domain.com";[/b]
            MailMessage mm = new MailMessage(cr, emc);


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

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

Open in new window


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

Line 401 is where the error is coming form.
string cr = "my@domain.com";

Stack:
Line 400:            string pt = "mypw";
Line 401:            string cr = "my@domain.com";
Line 402:            MailMessage mm = new MailMessage(cr, emc);

Open in new window


Thank you.
bmanmike39Asked:
Who is Participating?
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 = "my@domain.com";
            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?

EG:
       MailMessage mm = new MailMessage("my@domain.com", emc);
0
bmanmike39Author Commented:
emc contains the senders email address, also ours.  (sender@send.com, my@domain.com)

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 = ", my@domain.com, deptHhead@domain.com";
MailMessage mm = new MailMessage(cr, emc + ourcopys);

Open in new window

Thank you!
0
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".

eg:  
mm.Bcc.Add(ourcopys);

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("my@email.com"));
0

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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.