联系我们表格中的错误 [英] error in contact us form
本文介绍了联系我们表格中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
i有联系表格
来自:
主题:
消息正文:
但错误是此代码发送给我对我而言并没有定义来自电子邮件的文本框(textfrom)
this is my problem:
i have contact form with
from:
subject:
message body:
but the error is this code send from me to me and not define textbox that have from email(textfrom)
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("my account in gmail", "my password");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("test@yahoo.com");
msg.From = new MailAddress(textfrom.Text);
msg.Subject = txtSubject.Text;
msg.IsBodyHtml = true;
msg.Body = textbody.text;
try
{
client.Send(msg);
Label1.Text = "Your message has been successfully sent.";
}
catch (Exception ex)
{
Label1.ForeColor = Color.Red;
Label1.Text = "Error occured while sending your message." + ex.Message;
}
}
推荐答案
查看 MailAddress重载 [ ^ ]:
Look at the MailAddress overloads[^]:
msg.From = new MailAddress(fromAddress, fromDisplay, Encoding.UTF8);
这可能会解决您的问题。
有一个通用的电子邮件例程,它在这里完全正常工作:使用或不使用附件在C#中发送电子邮件:通用例程。 [ ^ ] - 那个也可以帮助你理解。
That may solve your problem.
There is a generic Email routine which is fully working here: Sending an Email in C# with or without attachments: generic routine.[^] - that may also help you understand.
这篇关于联系我们表格中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文