我正在尝试在Visual Studio 2013 MVC项目中使用Ajax.BeginForm发送邮件。
它可以在localhost或IIS上工作,我可以成功发送邮件,但是当我在服务器上发布时,却出现如下错误:
jquery-3.3.1.js:9600 POST http://draskinkaraca.com/Home/SendMail 500 (Internal Server Error)
“ /”应用程序中的服务器错误。 无法找到该资源。 说明:HTTP404。您正在寻找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用。请查看以下网址,并确保其拼写正确。
能帮我个忙吗?非常感谢。
请求的URL:/ Home / SendMail
这是我的Cshtml部分;
@using (Ajax.BeginForm("SendMail", "Home", FormMethod.Post, new AjaxOptions { OnSuccess = "OnSuccess", OnFailure = "OnFailure" }))
{
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Ad" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="surname" placeholder="Soyad" required>
</div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="email" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="tel" placeholder="Telefon" required>
</div>
<div class="form-group">
<textarea rows="5" id="message" name="message" class="form-control" placeholder="Mesajınız"></textarea>
</div>
<button type="submit" id="btnSendMail" class="btn">Gönder</button>
</form>
</div>
</div>
}
这是我的控制器部分;
[HttpPost]
public JsonResult SendMail(string name, string surname, string eMail, string tel, string message)
{
MailMessage ePosta = new MailMessage();
ePosta.From = new MailAddress("info@xxxx.com");
ePosta.To.Add("xxxx@hotmail.com");
ePosta.Subject = "Siteden gelen mail !!";
ePosta.SubjectEncoding = Encoding.UTF8;
ePosta.BodyEncoding = Encoding.UTF8;
ePosta.Body = "Ad Soyad : " + name + " " + surname + System.Environment.NewLine +
"Mail : " + eMail + System.Environment.NewLine +
"Telefon : " + tel + System.Environment.NewLine +
"Mesaj : " + message;
SmtpClient smtp = new SmtpClient();
//
smtp.Credentials = new System.Net.NetworkCredential("info@xxxx.com", "xxxx");
smtp.Port = 587;
smtp.Host = "webmail.xxxx.com";//webmail.xxxx.com
smtp.EnableSsl = false;
try
{
smtp.Send(ePosta);
}
catch (SmtpException ex)
{
throw new Exception("Mail Gönderme Hatasi", ex.InnerException.InnerException);
}
var result = "success";
return Json(result, JsonRequestBehavior.AllowGet);
}
这是我的脚本Jquery 3.3.1;
<script src="Scripts/jquery-3.3.1.js"></script>
<script src="assets/js/custom.js"></script>
<script src="Scripts/Index.js"></script>
<script src="Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="Scripts/toastr.js">