我需要创建一个按钮,将表中的信息按钮单击事件电子邮件 [英] I need to create a button that sends form information to email on button click event

查看:167
本文介绍了我需要创建一个按钮,将表中的信息按钮单击事件电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的一切程序,我在我个人的业务,提交表单细节上的按钮,单击电子邮件创建Web表单的过程。我已经做了搜索,我也不太能准确地找到我要找的。我不知道什么是通用的协议,当涉及到Web表单的提交。我宁可不要在数据库中的信息,因为它只是暂时的。虽然它可能是方便有提交到我的数据库中的姓名和电话号码上按一下按钮。

I'm new to everything programming and I'm in the process of creating a web form for my personal business that submits the form details to email on a button click. I've done a search, and I haven't quite been able to find exactly what I'm looking for. I'm not sure what common protocol is when it comes to web form submission. I would rather not have the information on a database, as it is only temporary. Though it might be handy to have a name and phone number submitted to my database on button click.

实际的电子邮件并不需要格式化好,我只需要从几个文本框的信息。我使用的TextBox1中 - TextBox6,如果这能帮助

The actual email doesn't need to be formatted well, I only need information from a few text boxes. I'm using TextBox1 - TextBox6, if that helps.

谢谢了,

推荐答案

您需要使用 System.Net.Mail 类来发送电子邮件在C#。邮件服务器设置都设置在在你的的web.config 文件中的 system.net mailsettings 部分。例如,电子邮件,通过Gmail帐户发送将使用以下设置:

You'll need to use the System.Net.Mail class to send emails in C#. The mail server settings are set up in your web.config file under the system.net mailsettings section. For example, email sent through a GMail account would use the following settings:

<system.net>
    <mailSettings>
      <smtp from="[email_address_here]">
        <network host="smtp.gmail.com" port="587" userName="[username]" password="[password]" enableSsl="true" />
      </smtp>
    </mailSettings>
</system.net>

然后,在按钮点击事件,您可以在Visual Studio中的按钮属性的事件部分访问,你可以把code收集表单信息,发送电子邮件,这将是这个样子

Then, on the button click event, which you can access in the Events section of the Button's properties in Visual Studio, you would put the code to gather the form information and send the email, which would look something like:

//Initiate the mail client.
SmtpClient mail = new SmtpClient();

//You would probably get the to email from your form using TextBox1.Text or something similar, or use your own to email.
MailMessage mm = new MailMessage("from_email", "to_email");

//Set the message properties, using your TextBox values to format the body of the email.
//You can use string format to insert multiple values into a string based on the order of {0}, {1}, {2} etc.
mm.Body = string.Format("Hi {0}, thanks for emailing me.", TextBox2.Text);
mm.IsBodyHtml = true; //Or false if it isn't a HTML email.
mm.Subject = "Your Subject Here";

//Send the email.
mail.Send(mm);

您还需要有行使用System.Net.Mail;你的code文件中使用的顶部 SMTPClient

这篇关于我需要创建一个按钮,将表中的信息按钮单击事件电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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