如何在电子邮件中发送HTML表单..而不仅仅是MAILTO [英] How do I send an HTML Form in an Email .. not just MAILTO

查看:116
本文介绍了如何在电子邮件中发送HTML表单..而不仅仅是MAILTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个供人填写的HTML表单,当他们点击提交按钮时,它只会发送电子邮件,不会发送他们的电子邮件并要求他们自己发送邮件。



当我使用时:

 < form action =MAILTO:emailaddress @ email.com...> 

所有这些都会打开一个新窗口并填充电子邮件的正文,但我希望它只需发送一封电子邮件即可。



有没有一种方法来格式化电子邮件的输出结果?而不仅仅是字段名称和输入值的列表。



谢谢。

解决方案

我实际上使用ASP C#发送我的电子邮件,看起来像这样:

  protected void Page_Load (object sender,EventArgs e)
{
if(Request.Form.Count> 0)
{
string formEmail =;
string fromEmail =from@email.com;
字符串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 =新的SmtpClient();

尝试
{
myMsg.To.Add(新的System.Net.Mail.MailAddress(defaultEmail));
myMsg.IsBodyHtml = true;
myMsg.Body = formEmail;
myMsg.From = new System.Net.Mail.MailAddress(fromEmail);
myMsg.Subject =使用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,使用gmail smpt发送,formEmail);


catch(Exception ee)
{
debug.Text + = ee.Message;


$ b $ / code $ / pre
$ b $ p这是一个使用gmail的例子作为smtp邮件发件人。这里的一些东西并不是必需的,但它是我使用它的方式,因为我确信有相同的方式有更多有效的方法。


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.

When I use:

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

Thanks.

解决方案

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;
        }
    }
}

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆