我的aspx页面iletisim.aspx
和html输入字段
<div class="contact-form">
<form name="contact-form" id="ContactForm" runat="server">
<div class="row clearfix">
<div class="col-md-6 col-sm-12 col-xs-12 form-group pull-right">
<textarea name="message" id="message" placeholder="Mesajınız"></textarea>
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<div class="row clearfix">
<div class="col-md-6 col-sm-6 col-xs-12 form-group">
<input type="text" name="username" id="username" placeholder="Adınız Soyadınız" required="" />
</div>
<div class="col-md-6 col-sm-6 col-xs-12 form-group">
<input type="email" name="email" id="email" placeholder="E-mailiniz" required="" />
</div>
<div class="col-md-6 col-sm-6 col-xs-12 form-group">
<input type="text" name="phone" id="phone" placeholder="Telefonunuz" required="" />
</div>
<div class="col-md-6 col-sm-6 col-xs-12 form-group">
<input type="text" name="subject" id="subject" placeholder="Mesaj Konusu" required="" />
</div>
<div class="col-md-12 col-sm-12 col-xs-12 form-group" id="submit-control">
<button type="submit" id="btn" name="submit-form">send Massage</button>
</div>
<div class="msg"></div>
</div>
</div>
</div>
</form>
</div>
C#代码
public static void sendMail_Click(string username, string email, string phone, string subject, string message)
{
try
{
string FilePath = HttpContext.Current.Server.MapPath("~/MailTemplateFormBilgi.html");
StreamReader str = new StreamReader(FilePath);
string MailText = str.ReadToEnd();
str.Close();
MailText = MailText.Replace("[musteriAd]", username);
MailText = MailText.Replace("[musteriEmail]", email);
MailText = MailText.Replace("[musteriTelefon]", phone);
MailText = MailText.Replace("[musteriKonu]", subject);
MailText = MailText.Replace("[musteriMesaj]", message);
SmtpClient mlClient = new SmtpClient();
MailMessage mlMessage = new MailMessage();
mlMessage.To.Add("serhat.gunes.92@gmail.com");
mlMessage.From = new MailAddress("bilgiislem@egemet.com.tr", "İletişim Formu Gelen Mail");
mlMessage.Subject = "Ferter Web Sitesi İletişim Formu Gelen Mail";
mlMessage.IsBodyHtml = true;
mlMessage.Body = MailText;
NetworkCredential guvenlikKarti = new NetworkCredential("serhat.gunes.92@gmail.com", "mypassword");
mlClient.Credentials = guvenlikKarti;
mlClient.Port = 587;
mlClient.Host = "smtp.gmail.com";
mlClient.EnableSsl = true;
mlClient.Send(mlMessage);
}
catch (Exception ex)
{
throw;
}
finally
{
}
}
我的外部js文件script.js
中的javascript代码可以正常工作,但是mail_gonder()
函数存在问题。例如,当我将警报消息写入success: function (data) {
时,没有结果。因此无需输入success: function (data) {
(function ($) {
var showDisableLayer = function () {
$("#submit-control").html("<img src=\"images/loading.gif\" style=\"width:100px;height:100px\"/> <span><b>Mesajınız gönderiliyor...</b></span>");
};
var hideDisableLayer = function () {
document.getElementById("submit-control").style.display = "none";
};
function mail_gonder() {
var username = document.getElementById("username").value,
email = document.getElementById("email").value,
phone = document.getElementById("phone").value,
subject = document.getElementById("subject").value,
message = document.getElementById("message").value;
jQuery.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "iletisim.aspx/sendMail_Click",
data: "{ 'username': '" + $('input[id$=username]').val() +
"', 'email': '" + $('input[id$=email]').val() +
"', 'phone': '" + $('input[id$=phone]').val() +
"', 'subject': '" + $('input[id$=subject]').val() +
"', 'message': '" + $('input[id$=message]').val() + "' }",
dataType: 'json',
async: false,
success: function (data) {
alert("Success");
jQuery('.msg')
.removeClass('msg-error');
jQuery('.msg')
.addClass('msg-success');
jQuery('.msg')
.text('Mesajınız Tarafımıza İletilmiştir, Teşekkürler');
hideDisableLayer();
},
error: function (data) {
jQuery('.msg')
.removeClass('msg-success');
jQuery('.msg')
.addClass('msg-error');
jQuery('.msg')
.text('Hata, Lütfen Daha Sonra Tekrar Deneyiniz');
hideDisableLayer();
}
});
hideDisableLayer();
}
(function ($) {
"use strict";
var $wn = $(window);
$wn.load(function () {
var $form = $("#ContactForm");
$form.dblclick = false;
if ($form.length > 0) {
$form.validate({
rules: {
username: {
required: true,
minlength: 3
},
email: {
required: true,
email: true
},
subject: {
required: true,
minlength: 3
},
phone: {
required: true,
minlength: 10,
number: true
},
message: {
required: true
}
},
messages: {
username: {
required: "bu alan gerekli.",
minlength: "en az 3 karakter giriniz."
},
email: {
required: "bu alan gerekli",
email: "gecerli bir e-mail adresi giriniz"
},
subject: {
required: "bu alan gerekli",
minlength: "en az 3 karakter giriniz."
},
phone: {
required: "bu alan gerekli",
number: "rakam giriniz",
minlength: "en az 10 karakter giriniz"
},
message: {
required: "bu alan gerekli"
}
},
submitHandler: function ($form) {
showDisableLayer();
setTimeout(mail_gonder, 2000);
}
});
}
});
})(jQuery);
})(window.jQuery);