【发布时间】:2019-03-22 04:33:22
【问题描述】:
我正在为我的公司建立一个网站,并且我在三个不同的页面上都有联系表格,带有不同的 URL。
有谁知道如何发送当前发送的 URL?
假设我在http://localhost:59379/en/about/ 上,我从这个 URL 发送一条消息,我希望这个 URL 发送到我的电子邮件。
喜欢:
邮件发送自:我邮箱中的{URL}。
我正在使用 SMTP
public void SendContactMail(string from, string name, string phone, string message)
{
try
{
var date = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
var newMail = new MailMessage { From = new MailAddress("HEY@LIVE.SE") };
newMail.To.Add(new MailAddress("hello@live.se"));
newMail.Subject = $"Contact {@date} form mail from: {@from}";
newMail.IsBodyHtml = true;
var body = $@"
{name} har fyllt i kontaktformuläret på ... <br/>
E-post: {@from}<br/>
Telefon:{phone} <br/>
Meddelande:{message}";
var view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
newMail.AlternateViews.Add(view);
Client.Send(newMail);
}
catch (Exception)
{
//some random stuff here.
}
}
HTML 表单:
<div class="col-xl-12">
<p class="text-white contact-us-title">Kontakta gärna oss!</p>
<input type="text" required class="form-control fc-contact" style="width:15rem;" placeholder="Namn" name="Name" aria-label="Recipient's username" aria-describedby="basic-addon2">
<br />
<input type="text" required class="form-control fc-contact" style="width:15rem;" placeholder="E-post" name="Email" aria-label="E-post" aria-describedby="basic-addon2">
<br />
<input type="text" required class="form-control fc-contact" style="width:15rem;" placeholder="Tele" name="Phone" aria-label="Tele" aria-describedby="basic-addon2">
<br />
<textarea class="form-control fc-contact" style="height:7rem; width:15rem; " placeholder="Meddelande" name="Message" aria-label="Message" aria-describedby="basic-addon2"></textarea>
<br />
<br />
<button type="submit" class="btn btn-success mb-5"><span>Skicka</span></button>
</div>
【问题讨论】:
-
抱歉忘记说我正在使用 Umbraco!试过但不工作
-
我得到了这个网址:"localhost:59379/umbraco/RenderMvc"
标签: c# html email smtp umbraco