【发布时间】:2018-10-22 00:01:15
【问题描述】:
首先,在我决定提出这个问题之前,我搜索并尝试了许多示例。 我正在 Visual Studio 2013 中用 C# 构建一个网站。
我有一个Contact page,上面有一个人们应该填写的表格。在我在这里和几个页面中搜索后,我无法为我的网站制作任何代码。
我怎样才能将表格中的信息发送到我的电子邮件?
控制器:
namespace SiteTESTE.Controllers
{
public class HomeController : Controller
{
public ActionResult Contacto()
{
return View();
}
HTML 代码:
<body>
<p>Se pretender mais informações sobre os nossos sistemas de relva artificial, produtos, orçamentos ou fichas técnicas, por favor não hesite em contactar-nos!</p>
<div class="container">
<div class="row">
<div class="column">
<div id="map" style="width:100%;height:500px"></div>
</div>
<div class="column">
<form action="/action_page.php">
<input type="text" id="fname" name="firstname" placeholder="O seu nome.." required>
<input type="text" id="lname" name="lastname" placeholder="O seu último nome.." required>
<input type="text" name="email" placeholder="Email" required>
<textarea id="subject" name="subject" placeholder="Escreva o seu texto.." style="height:170px" required></textarea>
<br />
<input type="submit" value="Enviar">
</form>
</div>
</div>
</div>
<script>
// Initialize google maps
function myMap() {
var myCenter = new google.maps.LatLng(51.508742, -0.120850);
var mapCanvas = document.getElementById("map");
var mapOptions = { center: myCenter, zoom: 12 };
var map = new google.maps.Map(mapCanvas, mapOptions);
var marker = new google.maps.Marker({ position: myCenter });
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
</body>
</html>
【问题讨论】:
-
您的
form标签在action属性中有一个PHP 页面作为目标。您将使用 PHP 还是 C# 来发送电子邮件? -
我忘记删除了,因为我从 w3schools 获得了一些代码。真诚的,我不知道该用什么。我不太了解 PHP,所以我想使用 C#。
-
好的。 (在我看来,W3School 非常糟糕)。简而言之:首先,您需要将表单内容发送到控制器中的操作。之后,您需要一个 C# 代码来发送电子邮件,您可以在此处查看示例:csharp.net-informations.com/communications/csharp-smtp-mail.htm
-
这是一个短代码。如何将我的表单内容发送到我的控制器?我一直在寻找,但我无法得出结论。如果我的电子邮件以“@hotmail.com”结尾,我应该选择哪个端口?
-
@jonysniper 我认为做一些基本的 MVC 教程会对你有所帮助。这就是他们所涵盖的确切类型。这样你会在更短的时间内学到更多。
标签: c# html asp.net asp.net-mvc contact-form