Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir ..

I have a registration form that has text boxes .i want to send a mail containaning all fields in the body of email..

here is my coding..i use this code but but these values is not showing in mail
C#
sendMailToAdmin(txtUsername.Text, txtFname.Text, txtCity.Text, txtEmail.Text, txtPhone.Text);

txtUsername.Text = "";
txtPassword.Text = "";
txtFname.Text = "";
txtCity.Text = "";
txtState.Text = "";
txtCountry.Text = "";
txtEmail.Text = "";
txtPhone.Text = "";

Response.Redirect("registered.aspx");
lblSuccess.Text = "Check Your Email For Login Information.<br>Your account will be activated within 48 hours.";

    protected void sendMailToAdmin(string uname, string name, string city, string email, string phone)
{
    MailMessage myMsg = new MailMessage();
    myMsg.From = new MailAddress("****@****.***);
    myMsg.To.Add(email);
    myMsg.Subject = "New User Email ";
    myMsg.Body = "New User Information";

    // your remote SMTP server IP.
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.Credentials = new System.Net.NetworkCredential("****@****.***", "********");
    smtp.EnableSsl = true;
    smtp.Send(myMsg);
}</br>
Posted
Updated 28-Jul-13 19:32pm
v2

Hello,

Try rewriting you function as shown below.
C#
protected void sendMailToAdmin(string uname, string name, string city, string email, string phone)
{
    MailMessage myMsg = new MailMessage();
    myMsg.From = new MailAddress("****@mail.com");
    myMsg.To.Add(email);
    myMsg.Subject = "New User Email ";
    myMsg.Body = "New User Information\n\nUser Name: " + uname + "\nFull Name : " + name + "\nCity : " + city + "\nEmail : " + email + "\nPhone : " +phone;

    // your remote SMTP server IP.
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.Credentials = new System.Net.NetworkCredential("****@mail.com", "pass***");
    smtp.EnableSsl = true;
    smtp.Send(myMsg);
}

Regards,
 
Share this answer
 
Comments
Swinky_Talwar 29-Jul-13 3:19am    
sir what is the code if i want to send this mail to 1 more email account of gmail...like one more copy of this mail
myMsg.IsBodyHtml = true;
myMsg.Body = txtUsername.Text+ "<br />"
             +txtPassword.Text + "<br />"
             +txtFname.Text+ "<br />"
             +txtCity.Text + "<br />"
             +txtState.Text+ "<br />"
             +txtCountry.Text+ "<br />"
             +txtEmail.Text+ "<br />"
             +txtPhone.Text ;

Regards..:laugh:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900