且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在电子邮件正文中发送文本框值。

更新时间:2022-11-07 18:30:26

你好,



尝试重写你的功能,如下所示。

  protected   void  sendMailToAdmin( string  uname, string  name, string  city, string  email, string 电话)
{
MailMessage myMsg = new MailMessage();
myMsg.From = new MailAddress( **** @ mail.com跨度>);
myMsg.To.Add(电子邮件);
myMsg.Subject = 新用户电子邮件;
myMsg.Body = 新用户信息\ n \\ n用户名: + uname + \ nFull名称: + name + \ nCity: + city + \ nEmail: +电子邮件+ \ nPhone: + phone ;

// 您的远程SMTP服务器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);
}



问候,


 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;



问候..:笑:


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

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>

Hello,

Try rewriting you function as shown below.
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,


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: