如何在电子邮件中发送 HTML 表单 .. 不仅仅是 MAILTO [英] How do I send an HTML Form in an Email .. not just MAILTO
问题描述
我有一个 HTML 表单供人们填写,我想要这样当他们点击提交按钮时,它只会发送电子邮件,而不是打开他们的电子邮件并要求他们自己发送消息.
I have an HTML form for people to fill out, and I want it so when they click the submit button, it will just send the email, not bring up their email and ask them to send the message themselves.
当我使用时:
<form action="MAILTO:emailaddress@email.com"... >
所做的只是打开一个新窗口并填充电子邮件的正文,但我希望它只发送一封电子邮件.
All that does is open up a new window and populates the body of the email, but I want it to just send an email.
有没有办法格式化电子邮件的输出格式?而不仅仅是字段名称和输入值的列表.
And is there a way to format the output of what the email will look like? Instead of just a list of the field names and the entered value.
谢谢.
推荐答案
我现在实际上使用 ASP C# 发送电子邮件,看起来像:
I actually use ASP C# to send my emails now, with something that looks like :
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form.Count > 0)
{
string formEmail = "";
string fromEmail = "from@email.com";
string defaultEmail = "default@email.com";
string sendTo1 = "";
int x = 0;
for (int i = 0; i < Request.Form.Keys.Count; i++)
{
formEmail += "<strong>" + Request.Form.Keys[i] + "</strong>";
formEmail += ": " + Request.Form[i] + "<br/>";
if (Request.Form.Keys[i] == "Email")
{
if (Request.Form[i].ToString() != string.Empty)
{
fromEmail = Request.Form[i].ToString();
}
formEmail += "<br/>";
}
}
System.Net.Mail.MailMessage myMsg = new System.Net.Mail.MailMessage();
SmtpClient smtpClient = new SmtpClient();
try
{
myMsg.To.Add(new System.Net.Mail.MailAddress(defaultEmail));
myMsg.IsBodyHtml = true;
myMsg.Body = formEmail;
myMsg.From = new System.Net.Mail.MailAddress(fromEmail);
myMsg.Subject = "Sent using Gmail Smtp";
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("testing@gmail.com", "pward");
smtpClient.Send(defaultEmail, sendTo1, "Sent using gmail smpt", formEmail);
}
catch (Exception ee)
{
debug.Text += ee.Message;
}
}
}
这是一个使用 gmail 作为 smtp 邮件发件人的示例.这里的一些内容不是必需的,但这是我使用它的方式,因为我相信有更有效的方法.
This is an example using gmail as the smtp mail sender. Some of what is in here isn't needed, but it is how I use it, as I am sure there are more effective ways in the same fashion.
这篇关于如何在电子邮件中发送 HTML 表单 .. 不仅仅是 MAILTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!